Skip to content

Instantly share code, notes, and snippets.

@joshblack
Created October 18, 2014 04:57
Show Gist options
  • Save joshblack/e46c344deb0f9f5ffc90 to your computer and use it in GitHub Desktop.
Save joshblack/e46c344deb0f9f5ffc90 to your computer and use it in GitHub Desktop.
[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