Created
September 8, 2018 06:25
-
-
Save mfalade/2af65a1ab9d0219c64139267e9d49f04 to your computer and use it in GitHub Desktop.
Basic Implementation of the array filter
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
Array.prototype.xfilter = myCustomArrayFilter; | |
function myCustomArrayFilter (action) { | |
var result = []; | |
for (var i = 0; i < this.length; i++) { | |
var args = [this[i], i, this]; | |
if (action.apply(null, args)) { | |
result.push(this[i]); | |
} | |
} | |
return result; | |
} | |
var greaterThen4 = [4, 5, 6].xfilter(x => x > 4); | |
console.log(greaterThen4, 'filter') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment