Created
September 6, 2017 21:36
-
-
Save nate-getch/f542ef3f912865e0523a0983fce10492 to your computer and use it in GitHub Desktop.
Extending Array object in js to filter odd and even elements of given array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = [1,2,3,4,5,6,7,8]; | |
Array.prototype.even = function(){ | |
let r = []; | |
r = this.filter( v => v % 2 == 0 ); | |
return r; | |
} | |
Array.prototype.odd = function(){ | |
let r = []; | |
r = this.filter( v => v % 2 != 0 ); | |
return r; | |
} | |
console.log(arr.even()); | |
console.log(arr.odd()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment