feat: new task

This commit is contained in:
2026-06-13 18:33:34 +07:00
parent 58a4b638ee
commit a487ef0dfe
6 changed files with 2213 additions and 0 deletions
+21
View File
@@ -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
}