Solve Using the array reduce method | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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.

25th Oct 2018, 1:23 PM
Onoh Light
Onoh Light - avatar
2 Answers
+ 1
function every(arr){ for(i=0;i<arr.length;i++){ if(!arr[i]){ return false } } return true }
25th Oct 2018, 2:21 PM
NicolasHM
NicolasHM - avatar
+ 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
25th Oct 2018, 7:40 PM
Andreas
Andreas - avatar