-
-
Save sethschori/dc4a80031d8843be5f48d41609783c3d to your computer and use it in GitHub Desktop.
https://repl.it/CgPh/12 created by sethopia
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
// Attach a method to the Array prototype called myFilter. | |
// It should be utilized and perform exactly as Array.prototype.filter does. Use the code snippet below as a guide. | |
Array.prototype.myFilter = function(func) { | |
var newArr = []; | |
for (var i = 0; i < this.length; i++) { | |
if(func(this[i],i,this)) { | |
newArr.push(this[i]); | |
} | |
} | |
return newArr; | |
}; | |
function isEven(num) { | |
return num % 2 === 0; | |
} | |
var arr = [0,1,2,3,4,5,6]; | |
var filtered = arr.myFilter(isEven); | |
console.log(filtered); // should be [ 0, 2, 4, 6 ] |
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
Native Browser JavaScript | |
>>> [ 0, 2, 4, 6 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment