Nodejs Array Even even()

Here you can find the source of even()

Method Source Code

Array.prototype.even = function(){
    let even = new Array();/* ww w  .  j a va 2s .c  o  m*/
    for(const e of this){
        if(!isNaN(e) && (e % 2 === 0))
            even.push(e);
    }
    return even;
}

Array.prototype.odd = function(){
    let odd = new Array();
    for(const e of this){
        if(!isNaN(e) && (e % 2 !== 0))
            odd.push(e);
    }
    return odd;
}

Array.prototype.first = function () {
    return this[0];
};
Array.prototype.sum = function() {
 
    let total = 0 ;
    for(const e of this)
    {
        if(isNaN(e))
            return null;
        total += e;
    }
    return total;
};

console.log([1,2,3,4,5,6,7,8,9,10].even());
console.log([1,2,3,4,5,6,7,8,9,10].odd());
console.log([1,2,3,4,5,6,7,8,9,10].first());
console.log([1,2,3,4,5,6,7,8,9,10].sum());

Related

  1. even()
    Array.prototype.even = function(){
      return this.filter( x => x % 2 == 0 )
    
  2. even()
    Array.prototype.even = function(){
        return this.filter((element) => element % 2 == 0);
    
  3. even()
    Array.prototype.even = function () { 
      return this.filter(function(value) { 
        return value % 2 == 0; 
      }); 
    
  4. even()
    Array.prototype.even = function () {
      return this.filter(function (e) {
        return !(e % 2);
      });
    };
    
  5. even()
    Array.prototype.even = function () {
      return this.filter((item) => {
        return item % 2 === 0;
      });
    };
    
  6. even()
    Array.prototype.even = function()
      var ret = new Array();
      this.forEach(function(a) {
        if (0 == a % 2) {
          ret.push(a);
      });
      return ret;
    ...
    
  7. even()
    Array.prototype.even = function(){
      var newArr = [];
      for (var i of this){
        if (i % 2 === 0){
          newArr.push(i);
      return newArr;
    
  8. even()
    Array.prototype.even = function(){
      return this.filter(x=> x%2 == 0?x:'');
    
  9. evens()
    Array.prototype.evens = function () {
      var a = [], o = this;
      for (var i = 0; i < o.length; i++) {
        if (i%2!=0) a.push(o[i]);
      return a;
    };