Here you can find the source of uniq()
"use strict";//from ww w . j a v a 2 s . c o m // dups Array.prototype.uniq = function () { let uniqueArray = []; for (let i = 0; i < this.length; i++) { if (uniqueArray.indexOf(this[i]) === -1) { uniqueArray.push(this[i]); } } return uniqueArray; }; console.log([1, 1, 2, 2, 3, 3, 4, 4, 5, 5].uniq()); // twoSum Array.prototype.twoSum = function () { const pairs = []; for (let i = 0; i < this.length; i++) { for (let j = (i + 1); j < this.length; j++) { if (this[i] + this[j] === 0) { pairs.push([i, j]); } } } return pairs; }; console.log([-1, 0, 2, -2, 1].twoSum()); // transpose Array.prototype.transpose = function () { const columns = []; for (let i = 0; i < this[0].length; i++) { columns.push([]); } for (let i = 0; i < this.length; i++) { for (let j = 0; j < this[i].length; j++) { columns[j].push(this[i][j]); } } return columns; }; console.log([[0, 1, 2], [3, 4, 5], [6, 7, 8]].transpose());
Array.prototype.uniq = function(){ var uniqArray = []; for (var i = 0; i < this.length; i++){ if (uniqArray.indexOf(this[i]) === -1) uniqArray.push(this[i]) return uniqArray ...
Array.prototype.uniq = function() { var temp = {}; for(var i=0; i<this.length; i++) { temp[this[i]] = 1; this.length = 0; for(var e in temp) { this.push(e); this.sort() return this; function xmlencode(string) { return string.replace(/\&/g,'&'+'amp;').replace(/</g,'&'+'lt;') .replace(/>/g,'&'+'gt;').replace(/\'/g,'&'+'apos;').replace(/\"/g,'&'+'quot;');
Array.prototype.uniq = function () { var uniq_arr = []; for (var i = 0; i < this.length; i++) { var included = false; for (var j = 0; j < uniq_arr.length; j++) { if (uniq_arr[j] === this[i]) { included = true; break; }; ...
Array.prototype.uniq = function() { let res = []; for(let i=0; i < this.length; i++) { let value = this[i]; if (!res.includes(value)) res.push(value); return res; }; console.log([1,2,2,1,1,3].uniq()); ...
Array.prototype.uniq = function () { var uniqueArray = []; for (var i = 0; i < this.length; i++) { if (uniqueArray.indexOf(this[i]) === -1) { uniqueArray.push(this[i]); return uniqueArray; }; ...
Array.prototype.uniq = function () { var newArray = []; for (var i = 0; i < this.length; i++) { var el = this[i]; if (newArray.indexOf(el) === -1) { newArray.push(el); return newArray; ...
Array.prototype.uniq = function() { var dups = {}, cleanArray = []; array = this, i = 0, len = array.length; if(this.constructor !== Array) { throw new TypeError ('Can only call this method on an array'); for(i; i < len; i++) { if(!dups[array[i]]) { cleanArray.push(array[i]); dups[array[i]] = true; return cleanArray;
Array.prototype.uniq = function (){ let result = []; for (let i = 0; i < this.length; i++) { if (result.includes(this[i])) { continue; } else { result.push(this[i]); return result; }; console.log([1, 2, 1, 3, 3].uniq()); console.log([1, 2, 3, 4].uniq());
var bubbleSort = function (array) var sorted = false; while (!sorted) sorted = true; for (i = 0; i < array.length - 1; i++) if (array[i] > array[i + 1]) ...