Nodejs Array Odd odd()

Here you can find the source of odd()

Method Source Code

Array.prototype.odd =  function() {
   var odd = function(value, index) {
      if ((index + 1) % 2) {
         return value;
      }//  w  w  w  .  j  a  v a2 s .  c  o  m
   };

   return this.filter(odd);
};

// usage

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

var aOdd = a.odd();

console.log(aOdd);

Related

  1. 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()); 
    console.log([1,2,3,6,5,3,4,7].odd()); 
    
  2. odd()
    Array.prototype.odd = function(){
      return this.filter( x => x % 2 != 0 )
    
  3. odd()
    Array.prototype.odd = function(){
        return this.filter((element) => element % 2 !== 0);
    
  4. odd()
    Array.prototype.odd = function () { 
      return this.filter(function(value) { 
        return value % 2 != 0; 
      }); 
    
  5. odd()
    Array.prototype.odd = function () {
      return this.filter(function (e) {
        return e % 2;
      });
    };