feat: new task
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
function cars(A = [0, 1, 0, 1, 1]) {
|
||||
let s = 0;
|
||||
const countedA = A.reverse().map(x => {
|
||||
if (!x) {
|
||||
return 0
|
||||
}
|
||||
s++;
|
||||
return s
|
||||
}).reverse();
|
||||
|
||||
let sum = 0;
|
||||
while(countedA.length) {
|
||||
const car = countedA.shift();
|
||||
if(car) {
|
||||
continue
|
||||
}
|
||||
const count = countedA.find(n => n > 0);
|
||||
sum = sum + count;
|
||||
}
|
||||
return sum
|
||||
}
|
||||
Reference in New Issue
Block a user