Created
July 31, 2016 19:50
-
-
Save anonymous/9e8d1e9fede18f5d4701e270b57f97a6 to your computer and use it in GitHub Desktop.
https://repl.it/CgPm/32 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 myMap. | |
// It should be utilized and perform exactly as Array.prototype.map does. Use the code snippet below as a guide. | |
Array.prototype.myMap = function(callback) { | |
var returnArr = []; | |
for (var i = 0; i < this.length; i++) { | |
returnArr.push(callback(this[i],i,this)); | |
} | |
return returnArr; | |
} | |
function valPlusInd(val, index) { | |
return val + index; | |
} | |
var arr = [1,2,3,4,5]; | |
var mapped = arr.myMap(valPlusInd); | |
console.log(mapped); // Should be [ 1, 3, 5, 7, 9 ] | |
function addWorld(str) { | |
return str + ' World'; | |
} | |
var arr2 = ['Hello', 'Great', 'Big']; | |
var mapped2 = arr2.myMap(addWorld); | |
console.log(mapped2); // Should be [ 'Hello World', 'Great World', 'Big World' ] | |
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 | |
>>> [ 1, 3, 5, 7, 9 ] | |
[ 'Hello World', 'Great World', 'Big World' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment