Nodejs Array All Predicate all(p)

Here you can find the source of all(p)

Method Source Code

// Description:/*from   w w  w  . j  ava 2 s  . c om*/

// As a part of this Kata, you need to create three functions that one needs to be able to call upon an array:

// all

// This function returns true only if the predicate supplied returns true for all the items in the array

// [1, 2, 3].all(isGreaterThanZero) => true
// [-1, 0, 2].all(isGreaterThanZero) => false
// none

// This function returns true only if the predicate supplied returns false for all the items in the array

// [-1, 2, 3].none(isLessThanZero) => false
// [-1, -2, -3].none(isGreaterThanZero) => true
// any

// This function returns true if at least one of the items in the array returns true for the predicate supplied

// [-1, 2, 3].any(isGreaterThanZero) => true
// [-1, -2, -3].any(isGreaterThanZero) => false
// You do not need to worry about the data supplied, it will be an array at all times.

Array.prototype.all = function (p) {
  for (var i = 0; i <this.length; i++){
    if (p(this[i]) === false){
      return false;
    }
  }
  return true;
};

Related

  1. all(p)
    Array.prototype.all = function (p) {
      for(var i = 0; i < this.length; i++){
        if(!p(this[i])) return false;
      return true;
    };
    
  2. all(p)
    Array.prototype.all = function (p) {
     return this.filter(p).length == this.length;
    };
    
  3. all(p)
    Array.prototype.all = function (p) {
      for (i = 0; i < this.length; i++)
        if (!p(this[i])) return false;
      return true;
    };
    
  4. all(p)
    Array.prototype.all = function (p) {
      for(let el of this){
        if(!p(el)) {return false;}
      return true;
    };
    
  5. all(p)
    Array.prototype.all = function (p) {
      return (this.filter(p).length === this.length);
    };
    Array.prototype.none = function (p) {
      return (this.filter(p).length === 0);
    };
    Array.prototype.any = function (p) {
      return (this.filter(p).length > 0);
    };
    ...
    
  6. all(predicate)
    Array.prototype.all = function(predicate){
      for (var i = 0; i < this.length; i++){
        if (!predicate(this[i])) {
          return false
      return true
    
  7. all(predicate, context)
    Array.prototype.all = function (predicate, context) {
      context = context || window;
      predicate = predicate || Predicate;
      var f = this.every || function (p, c) {
        return this.length == this.where(p, c).length;
      };
      return f.apply(this, [predicate, context]);
    };
    
  8. allItemsAre(xAndY)
    Array.prototype.allItemsAre = function(xAndY){
       for(var i = 0; i < this.length; i++)
        if(!xAndY(this[i])){
          return false;
      return true;
    
  9. allItemsAre(xAndY)
    Array.prototype.allItemsAre = function(xAndY){
         for(var i = 0; i < this.length; i++)
        if(!xAndY(this[i])){
          return false;
      return true;