Skip to content

Instantly share code, notes, and snippets.

@holtbp
Created March 22, 2012 00:35
Show Gist options
  • Save holtbp/2154593 to your computer and use it in GitHub Desktop.
Save holtbp/2154593 to your computer and use it in GitHub Desktop.
Duplicating an Array
// 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