Created
March 22, 2012 00:35
-
-
Save holtbp/2154593 to your computer and use it in GitHub Desktop.
Duplicating an Array
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
// Given an array, var arr = [1,2,3,4,5] how do you implement a function duplicator such that | |
// arr.duplicator() == [1,2,3,4,5,1,2,3,4,5]? | |
Array.prototype.duplicator = function() { | |
return this.concat(this); | |
}; | |
var arr = [1,2,3,4,5], | |
dupe = arr.duplicator(); | |
console.log(dupe); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment