+ 1
Solve Using the array reduce method
Write a function named every that has one parameter: arr - an array of booleans The function returns true if every element in the array is true, otherwise, it returns false. If the array is empty, it defaults to true.
2 Antworten
+ 1
function every(arr){
for(i=0;i<arr.length;i++){
if(!arr[i]){ return false }
}
return true
}
+ 1
something like this?:
function every (arr) {
return !arr.length || arr.reduce(function(acc,curr) {
return curr && acc === curr
});
}
https://code.sololearn.com/Wq5WeuW7stK6/?ref=app