Javascript Array even()

Description

Javascript Array even()


Array.prototype.even = function(){
    return this.filter((v,i)=>i%2==1);
}
Array.prototype.odd = function(){
    return this.filter((v,i)=>i%2==0);
}

console.log([1,2,3,4,5,6,7,8].even());//ww  w .j a v a 2s.  com
console.log([1,2,3,4,5,6,7,8].odd());

Javascript Array even()

Array.prototype.even = function () {
    return this.filter( x => (x % 2) == 0 );
};

Array.prototype.odd = function () {
    return this.filter( x => ( x % 2 ) == 1 );
};


var arrEven = [1,2,3,4,5,6,7,8].even();
console.log(arrEven);/*from   w w  w  .  j  a  v  a  2 s .c o m*/

var arrOdd = [1,2,3,4,5,6,7,8].odd();
console.log(arrOdd);

Javascript Array even()

Array.prototype.even = function(){
  return this.filter(a=>a % 2 === 0);
}

Javascript Array even()

Array.prototype.even = function(){
  return this.filter( x => x % 2 == 0 )
}

Javascript Array even()

Array.prototype.even = function(){
    return this.filter((element) => element % 2 == 0);
}

Javascript Array even()

Array.prototype.even = function () { 
  return this.filter(function(value) { 
    return value % 2 == 0; 
  }); // w  w w  .j a v  a  2 s  . c o  m
}

Javascript Array even()

Array.prototype.even = function() { return this.filter(n => n % 2 == 0)};

Javascript Array even()

Array.prototype.even = function(){
  return this.int().filter(function (x) { return ~x & 1 });
}

Javascript Array even()

Array.prototype.even = function(){
    return this.filter(function(e){return e%2 == 0;});
}

Javascript Array even()

Array.prototype.even    = function () { return this.filter(function(item) { return 0 === item % 2; }); };

Javascript Array even()

Array.prototype.even = function() {
    return this.filter(function(e) {
        return !(e % 2)
    })//w w w.j  a v  a2 s  .c om
};

Javascript Array even()

Array.prototype.even = function () {
  return this.filter(function(item) {
    return 0 == item % 2;
  });//ww w .j a  va  2  s. c  o m
}

Javascript Array even()

Array.prototype.even = function () {
  return this.filter(function(number) {
      return number % 2 == 0;
    });/*w w w .ja v a2s.c o  m*/
}

Javascript Array even()

Array.prototype.even = function() {
  return this.isInt().filter(function(n) { return n%2===0 });
}

Javascript Array even()

Array.prototype.even = function(){
    let even = new Array();
    for(const e of this){
        if(!isNaN(e) && (e % 2 === 0))
            even.push(e);//from  w  ww.  j a v a  2s .  c  om
    }
    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());

Javascript Array even()

Array.prototype.even = function(){
    let arr = this.filter(elem => Number.isInteger(elem)).map(elem => parseInt(elem));
    return arr.filter(elem => elem % 2 === 0);
}
Array.prototype.odd = function(){
  let arr = this.filter(elem => Number.isInteger(elem)).map(elem => parseInt(elem));
  return arr.filter(elem => elem % 2 > 0);
}
Array.prototype.under = function(x){
  let arr = this.filter(elem => Number.isInteger(elem));
  return arr.filter(elem => elem < x);
}
Array.prototype.over = function(x){
  let arr = this.filter(elem => Number.isInteger(elem));
  return arr.filter(elem => elem > x);
}
Array.prototype.inRange = function(min,max){
  let arr = this.filter(elem => Number.isInteger(elem));
  return arr.filter(elem => elem >= min && elem <= max);
}

Javascript Array even()

Array.prototype.even = function() {
    var even = [];
    for(var i = 0; i < this.length; i++)
        if(this[i] % 2 == 0) even.push(this[i]);
    return even;/*w  ww  .j a v a 2s. c  o m*/
}

Javascript Array even()

Array.prototype.even = function (){
  var result = new Array();
  this.forEach(function(v){
    if(v%2 == 0){
      result.push(v);//from   w w  w.  j a  v a 2  s  .c  o m
    }
  });
  return result;
};

Javascript Array even()

Array.prototype.even = function(){
  return this.filter(function(element){
    return element%2 ===0;
  });/*  www.j  av  a 2  s  . c  o  m*/
};



PreviousNext

Related