every function for javascript arrays

Checks every element of an array(data) by a given condition(validate).


every.js
module.exports = function (data, validate){
  for(var i = 0; i < data.length; i++) {
    if(validate(data[i]) === false) {
      return false;
    }
  }

  return true;
}

Share This Post