Skip to content

Instantly share code, notes, and snippets.

@ramsunvtech
Created September 25, 2018 20:57
Show Gist options
  • Save ramsunvtech/9a30430f6b175a744357a96a2b004100 to your computer and use it in GitHub Desktop.
Save ramsunvtech/9a30430f6b175a744357a96a2b004100 to your computer and use it in GitHub Desktop.
Array Multiply Prototype Method
let integerLists = [1,2,3];
Array.prototype.multiply = function (callback) {
let list = [];
for(let i= 0; i < this.length; i++) {
list.push(callback(this[i], i));
}
return list;
};
let multipliedLists = integerLists.multiply(function (item, index) {
return item * 2;
}); // [2,4,6];
// Without Prototype using map
[1,2,3].map(i => i * 2); // [2,4,6];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment