Predicate Every and Some on array - Node.js Array

Node.js examples for Array:Array Operation

Description

Predicate Every and Some on array

Demo Code


function every(array, test) {
  for (var i=0;i<array.length;i++){
    if (test(array[i]) != true) {
      return false;
    }/*w w w  .jav a2  s. c  om*/
  }
  return true;
}

function some(array, test) {
  for (var i=0;i<array.length;i++){
    if (test(array[i]) === true) {
      return true;
    }
  }
  return false;
}

console.log(every([NaN, NaN, NaN], isNaN));
// true
console.log(every([NaN, NaN, 4], isNaN));
//false
console.log(some([NaN, 3, 4], isNaN));
//
console.log(some([2, 3, 4], isNaN));
//

Related Tutorials