This is part of the code that implements the structure pseudo class Type-of-type:
<script type= "Text/javascript" > var ret= ["Span", "span", "strong", "span", "B"] var norepeat = function (array) {var Set = Array.join (",") + ","; while (Array.Length) {var el = Array.shift (); Set = Set.replace (el+ ",", ""); if (Set.indexof (el+ ",")!=-1) {set = Set.replace (New RegExp (el+ ",", "G"), ""); Array = Set.replace (/,$/g, ""). Split (","); }else{set = el+ "," +set; } return Set.replace (/,$/g, ""). Split (",")} alert (Norepeat (ret))//last returned B,strong </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Feel the effect is not high, to worry-free master for help. Here is the customer service fruit (good and powerful replacement AH):
<script language= "JavaScript" > var ret= ["Span", "span", "strong", "span", "B"]; var norepeat=function (x) {var y= ' C0CB5F0FCF239AB3D9C1FCD31FFF1EFC '; Return X.sort (). Join (y). Replace (RegExp (' (. * (' +y+ ' |$)) \\1+ ', ' g '), '). Split (y); }; Alert (Norepeat (ret)); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Abcdreamer implementation (This implementation can filter the repetition in an array of impure strings, I prefer):
<script language= "JavaScript" > var a = ["span", "span", "strong", "span", "B"]; function Norepeat (a) {var i = a.length, j, B; while (i--) {j = i; b = false; while (j--) {if (a[i] = = A[j]) {A.splice (J, 1); i--; B = true; } if (b) A.splice (I, 1); return A; Alert (Norepeat (a)); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
Which Master has a better implementation, please let me know!
It seems that some people do not understand the difference between the Norepeat function and the unique function, Norepeat is to remove the duplicate elements in the array, if there are two a in the array, then remove the two, the unique will remove one of them. Here is the implementation of the unique function:
<script language= "JavaScript" > Array.prototype.inArray = Function (EL) {for (Var i=0,n=this.length;i<n;i++) if (This[i]===el) return true; return false; } Array.prototype.unique = function () {var i = 0, n = this.length,ret = []; for (; i < n; i++) if (!ret.inarray (this[i)) Ret.push (this[i)); return ret; }; var ret= ["Span", "span", "strong", "span", "B"] alert (Ret.unique ())//Back to "span", "strong", "B" </script>
[ctrl+a All selected note: If you need to introduce external JS need to refresh to perform]