Here you can find the source of duplicate()
Array.prototype.duplicate = function(){ var newArr = this.slice(); for(var i = 0; i < this.length; i ++){ newArr.push(this[i]);/*from w w w.j a v a 2s .co m*/ } return newArr; }; console.log([1, 2, 3, 4].duplicate());
Array.prototype.duplicate = function() { return (this + ',' + this); };
Array.prototype.duplicate = function(){ return this.concat(this); duplicate([1,2,3,4,5])
function duplicateArray(arr) { return arr.concat(arr); Array.prototype.duplicate = function() { return this.concat(this); console.log([1,2,3,4,5].duplicate()); console.log(duplicateArray([1,2,3,4,5]));
Array.prototype.duplicate = function(){ var arrayVal = this; this.forEach(function(val){ arrayVal.push(val); }) return arrayVal;
var arr1 = [3, 'a', 'a', 'a', 2, 3, 'a', 3, 'a', 2, 4, 9, 3]; Array.prototype.duplicate = function () { return this.concat(this); console.log([4, 5, 6, 7, 7].duplicate());