Q:

Write a JavaScript function that returns true if the provided predicate function returns true for all elements in a collection, false otherwise

0

Write a JavaScript function that returns true if the provided predicate function returns true for all elements in a collection, false otherwise.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const all = (arr, fn = Boolean) => arr.every(fn);
console.log(all([4, 2, 3], x => x > 1)); 
console.log(all([4, 2, 3], x => x < 1));
console.log(all([1, 2, 3])); 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now