Here you can find the source of dups()
Array.prototype.dups = function() { var result = []; for(var i = 0; i < this.length; i++){ if (result.indexOf(this[i]) === -1) { result.push(this[i]);// ww w . ja v a 2 s . co m } } return result; } // console.log([1,1,1,2,2,2,3].dups());
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());
function duplicate(arr) { var len = arr.length; for (var i = 0; i < len; i++) { console.log(arr[i]); arr[len + i] = arr[i]; return arr; Array.prototype.duplicate = function () { ...
Array.prototype.duplicator = function() { var len = this.length; for (var i = 0; i < len; i++) { this.push(this[i]); return this; }; console.log([1, 2, 3, 4, 5].duplicator());
Array.prototype.dups = function () { const uniqArr = []; for (var i = 0; i < this.length; i++) { if (!uniqArr.includes(this[i])){ uniqArr.push(this[i]); return uniqArr; }; ...