I saw this solution on codewars
"strict mode";
let testarr = [true,true,false,true,true];
function countSheeps(arrayOfSheeps) {
return arrayOfSheeps.filter(Boolean).length;
}
console.log(countSheeps(testarr))
How does this work? I thought that for the filter method to work a function must be passed into it rather than a data type or value. I tried this with an array of numbers and replaced the word "boolean" with "number" and also actual numbers eg 3. Yet this didnt work - So why does it work with boolean here?
Booleanobject is not a data type. trytypeof BooleanBooleanis a function.