function and(arr) {
if (arr.length === 0) {
return true;
}
const head = arr[0];
const tail = arr.slice(1);
return head && and(tail);
}
and([true, true, false]);
I have this recursion called 4 times and at the end
if (arr.length === 0) {
return true;
}
I thought it would end with
However, the function has only been called 3 times !!
head: [true] tail: [true,false]
head: [true] tail: [false]
head: [false] tail: []
This is the result I checked
if (arr.length === 0) {
return true;
}
This condition didn't even work.
I need help.
Sorry for using the translator
return head && and(tail);toreturn and(tail);.true, which goes against the whole point of the function.