Last active
September 23, 2015 11:16
-
-
Save violarium/d817f599c1c35a402e12 to your computer and use it in GitHub Desktop.
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
function each(array, callback) { | |
var i, length = array.length; | |
for (i = 0; i < length; i += 1) { | |
callback(array[i]); | |
} | |
} | |
function map(array, callback) { | |
var newArray = []; | |
each(array, function (item) { | |
newArray.push(callback(item)); | |
}); | |
return newArray; | |
} | |
// Example | |
var a = [1, 2, 3]; | |
var newA = map(a, function (item) { | |
return item * 2; | |
}); | |
console.log(newA); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment