Skip to content

Instantly share code, notes, and snippets.

@violarium
Last active September 23, 2015 11:16
Show Gist options
  • Save violarium/d817f599c1c35a402e12 to your computer and use it in GitHub Desktop.
Save violarium/d817f599c1c35a402e12 to your computer and use it in GitHub Desktop.
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