The example of this article summarizes the method of jquery implementation to remove duplicate strings. Share to everyone for your reference, specific as follows:
Here's a summary of three ways to remove duplicate strings:
Put the example on, with jquery convenient, first of all, to build the environment, in the same directory (under the same folder) to ensure that the use of jquery1.8.1 (if the other version of the HTML code in the corresponding changes)
First:
Description: Usually the string is divided into groups, and then the array of operations, relative to the method of more arrays, more convenient, and finally join into a string
With respect to the sort () method, the array elements are sorted first, because the same characters can be grouped together, so there is no need to double loop, or you have to get each element, and the rest of each match, and this sort will be sorted in ascending order of ASCII characters.
Second:
Note that this unique method is really convenient, but has two drawbacks:
1, only the array is valid (the direct string does not work), and it cannot be a numeric array,
2, only the adjacent repeated elements of the effective, separated not.
For example: [A,A,B,B,C,C]---unique----[a,b,c] Valid
[A,a,b,b,c,c,a]--unique-->[a,b,c,a] Element A is still duplicated, invalid
So before calling unique, you must call the Sort method to rearrange its repeating elements and get together
But also because the sort method is called, the order is b,b,c,c,a,a as follows: [The]---unique-->[a,b,c] is not [b,c,a]
Third:
Description
var reg =/(.) (? =.*\1)/g;
. matches any character, but can only match one of any characters
(.) Plus () is to store the matching character for later reference
(? =) Pre-search (also called assertion, also known as the pre-check), to indicate what the right side of a character, but does not contain this part, just take this ' one character '
such as: P (? =ing) matches the string ping when the match succeeds, but the matching character is P is not ping
(=.*\1) This \1 is the front of the finger (.) This character, said before it was added parentheses is stored up, now \1 is the first to take storage (a total)
* Number of matches, also known as quantifiers, refers to the occurrence of any time
. * refers to any occurrence of any character at any time
(.) (? =.*\1) refers to the first matching character that matches the character when it appears in the content on the right
G refers to globle, global matching pattern, matching all strings
The result of this heavy weight is actually inverted to sort, that is, repeated characters appear in front of the is empty, is a character from the back of the sequence
Another: about the heavy interest of friends can also refer to the site online tools :
Online removal of duplicates tool
More on jquery related content to view the site topics: "jquery Operation XML Skills Summary", "jquery drag and drop effects and tips summary", "JQuery Extended Skills Summary", "jquery common Classic Effects Summary", "jquery animation and special effects usage Summary", " jquery Selector Usage Summary and "jquery Common Plug-ins and Usage summary"
I hope this article will help you with the jquery program design.