Created
July 31, 2016 19:50
-
-
Save anonymous/23a2d2cdacea2088f2aa06a01f895bf0 to your computer and use it in GitHub Desktop.
https://repl.it/CgPo/37 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 myForEach. | |
// It should be utilized and perform exactly as Array.prototype.forEach does. Use the code snippet below as a guide. | |
Array.prototype.myForEach = function(callback) { | |
for (var i = 0; i < this.length; i++) { | |
callback(this[i],i,this); | |
} | |
} | |
var sum = 0; | |
function addToSum(num) { | |
sum += num; | |
} | |
var arr = [1,2,3]; | |
arr.myForEach(addToSum); | |
console.log(sum); // 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 | |
>>> 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment