Skip to content

Instantly share code, notes, and snippets.

@yitonghe00
Created April 17, 2020 05:35
Show Gist options
  • Save yitonghe00/36d77c8aab24bc47cb74d732eca5552d to your computer and use it in GitHub Desktop.
Save yitonghe00/36d77c8aab24bc47cb74d732eca5552d to your computer and use it in GitHub Desktop.
/*
function every(array, test) {
// Your code here.
for (let elem of array) {
if (!test(elem)) return false;
}
return true;
}
*/
function every(array, test) {
// Your code here.
return !array.some((elem) => !test(elem));
}
console.log(every([1, 3, 5], n => n < 10));
// → true
console.log(every([2, 4, 16], n => n < 10));
// → false
console.log(every([], n => n < 10));
// → true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment