Due to the existence of a parallel selector, the deduplication problem still exists even if the result set is filtered from right to left. The sorting problem has been mentioned. JK has previously provided a very backwardAlgorithm. Now let's take a look at the deduplication problem. In fact, you can think of it as a pure array deduplication problem. The difficulty lies in speed. Therefore, mootools developed slickspeed, which triggered a speed competition. Now let's take a look at the implementation of several de-duplicated functions.
VaR unique = function (array) {var ret = []; O: For (VAR I = 0, n = array. length; I
This is an early mass framework solution without disrupting the order.
Function uniq (array) {var ret = [], rI = 0 array = array. sort (); RET [ri] = array [0]; for (VAR j = 1, n = array. length; j <n; j ++) {If (Ret [ri]! = Array [J]) {RET [++ Ri] = array [J]} return ret ;}
This is disordered.
/* fast deduplication, relative to arrayh. unique: for efficiency, the Code volume and rigor are removed. If the array contains objects that cannot add attributes, an error is thrown. * @ method quicklyunique * @ static * @ Param {array} array to be processed * @ return {array} returns the new array after deduplication */quicklyunique: function (ARR) {var STRs ={}, numandbls ={}, objs = [], hasnull, hasundefined, ret = []; for (VAR I = 0, Len = arr. length; I
This is a solution provided by the qwrap framework. It uses the classic hash deduplication method, but this requires some measures for the elements of the object type. Therefore, it is only a candidate case. Like the popular Common hash deduplication methods on the Internet, it cannot be inferred.
Unique: function (ARR) {var rlt = [], OI = NULL, indexof = array. indexof | arrayh. indexof; For (VAR I = 0, Len = arr. length; I <Len; I ++) {If (indexof (rlt, OI = arr [I]) <0) {RLT. push (OI) ;}} return rlt ;},
This is the current qwrap solution. It uses native array. Prototype. indexof and does not support making a wheel on its own.
Unique: function (target) {var ret = [], n = target. length, I, j; for (I = 0; I <n; I ++) {for (j = I + 1; j <n; j ++) if (target [I] === target [J]) J = ++ I; ret. push (target [I]);} return ret ;},
This is the scheme that mass framework is using and is provided by the ABCD in the group.
Sizzle. uniquesort = function (results) {If (sortorder) {hasduplicate = basehasduplicate; results. Sort (sortorder); If (hasduplicate) {for (VAR I = 1; I
This is the solution before jquery 1.7 and operates directly on the original array. If the array is large, ie6. Because the processing is a node, to maintain the same effect as queryselectorall, we need to sort the result in order in the DOM tree.
Sizzle. uniquesort = function (results) {var ELEM, I = 1; hasduplicate = basehasduplicate; results. sort (sortorder); If (hasduplicate) {for (; (ELEM = Results [I]); I ++) {If (ELEM = Results [I-1]) {results. splice (I --, 1) ;}} return results ;};
Jquery1.8, which no longer accesses the Length attribute of the array, improves the running efficiency. Whether the existence of the condition is a cyclic condition after each value is assigned with ELEM = Results [I.
Sizzle. uniquesort = function (results) {var ELEM, duplicates = [], I = 1, j = 0; hasduplicate = basehasduplicate; results. sort (sortorder); If (hasduplicate) {for (; (ELEM = Results [I]); I ++) {If (ELEM = Results [I-1]) {J = duplicates. push (I) ;}while (j --) {results. splice (duplicates [J], 1) ;}} return results ;};
In jquery1.83, the index value is maintained first and then deleted from the end to avoid deletion errors caused by array index changes.
But obviously jquery. Unique cannot be used to remove duplicates from ordinary arrays. Therefore, they are irrelevant two functions in the mass framework.