Created
October 18, 2014 04:57
-
-
Save joshblack/e46c344deb0f9f5ffc90 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[1, 2, 3, 4, 5].duplicate(); | |
// My initial attempt | |
Array.prototype.duplicate = function() { | |
var arr = this.slice(0); | |
arr.forEach(function(e) { | |
arr.push(e); | |
}); | |
return arr; | |
} | |
// Easy way | |
Array.prototype.duplicate = function() { | |
return this.concat(this); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment