Created
November 14, 2018 04:54
-
-
Save Anenth/3d967c7130108c82377f524f0b61567d to your computer and use it in GitHub Desktop.
Array multiple with prototype
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
Array.prototype.multiply = function(){ | |
const le = this.length; | |
for(let i=0; i < le; i++){ | |
this[i+le] = this[i]*this[i]; | |
console.log(this) | |
} | |
}; | |
const a = [1, 2, 3, 4, 5]; | |
a.multiply(); | |
console.log(a); //[1, 2, 3, 4, 5, 1, 4, 9, 16, 25] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment