Javascript Array odd()

Description

Javascript Array odd()


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


console.log([1,2,3,6,5].even()); // 2,6
console.log([1,2,3,6,5,3,4,7].odd()); // 1,3,5,3,7

Javascript Array odd()

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


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



const numbers = [1,2,3,4,5,6,7,8];

console.log(numbers.odd());/*from ww w .jav a  2 s  .  c om*/
console.log(numbers.even());

Javascript Array odd()

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

Javascript Array odd()

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

Javascript Array odd()

// augmentation/*from w w  w . java  2  s  . c  om*/

Array.prototype.odd =  function() {
 var odd = function(value, index) {
  if ((index + 1) % 2) {
   return value;
  }
 };

 return this.filter(odd);
};

// usage

var a = [1, 2, 3, 4, 'odd', 'even'];

var aOdd = a.odd();

console.log(aOdd);

Javascript Array odd()

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

Javascript Array odd()

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

Javascript Array odd()

Array.prototype.odd = function () { 
  return this.filter(function(value) { 
    return value % 2 != 0; 
  }); /*from  w w w.j  a v a  2 s.  c  om*/
}

Javascript Array odd()

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

Javascript Array odd()

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

Javascript Array odd()

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

Javascript Array odd()

Array.prototype.odd = function() {
    return this.filter(function(e) {
        return e % 2
    })//from  w  ww . j  a v  a  2s .  co m
};

Javascript Array odd()

Array.prototype.odd = function () {
  return this.filter(function(item) {
    return 0 != item % 2;
  });//w  w  w .  j  av a2  s  . com
}

Javascript Array odd()

Array.prototype.odd = function () {
  return this.filter((item) => {
    return item % 2 === 1;
  });//from   w ww .  ja v a  2s .c  o m
};

Javascript Array odd()

Array.prototype.odd = function () {
  return this.filter(function(number) {
      return number % 2 !== 0;
    });//from   w ww.  ja v  a  2 s  .co  m
}

Javascript Array odd()

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

Javascript Array odd()

Array.prototype.odd = function() {
    var odd = [];
    for(var i = 0; i < this.length; i++)
        if(this[i] % 2 == 1) odd.push(this[i]);
    return odd;/*  www.j ava 2s  . c o m*/
}

Javascript Array odd()

Array.prototype.odd = function (){
  var result = new Array();
  this.forEach(function(v){
    if(v%2 != 0 && v%1 == 0){
      result.push(v);//from   www  . ja  v a  2s  .c  o m
    }
  });
  return result;
};

Javascript Array odd()

Array.prototype.odd = function(){
  return this.filter(function(element){
    return element%2 ===1;
  });/*from  w ww .  ja v  a 2  s.c om*/
};





let numbers  = [1,2,3,4,5];
console.log("square",numbers.square());
console.log("cube",numbers.cube());
console.log("sum",numbers.sum());
console.log("average",numbers.average());
console.log("even",numbers.even());
console.log("odd",numbers.odd());



PreviousNext

Related