Deduplication of repeated array items

Source: Internet
Author: User
 1 <!DOCTYPE HTML> 2 

1. First, we have two arrays. One in array A has a value. The other is array B. The other is array B.

The idea is as follows: when we put the array in array a into array B one by one, if we find that there is the same number as the number in array B, we will not put the items in array a de-duplicated like this.

Line 20 of the Code: declare an array A (there are many repeated items in array)

Line 21 of the Code: declare an array B (B is an empty array to display the de-duplicated Effect of array)

For (VAR I = 0; I <. length; I ++) // traverse array a 24 {25 if (fun (A [I]) // execute a function this function is fun () in addition, each value in array a is passed to the fun function. In this function, 26 {27 continue; // If the returned value is true, the function executes the continue (that is, it does not continue to be put into array B) 28} 29 else {30 B. push (A [I]); // if the return value of the function is false, insert a [I] 31 to array B}
        

Function fun (AAA) {// fun () Is the function 33 for (var ii = 0; II <B. length; II ++) // first, we need to traverse the array B, which is also an empty array so that we can know whether the values in array a are repeated 34 {35 if (B [II] = aaa) // if the value of B [II] is found to be AAA (AAA is the input parameter. this parameter is the value of a [I] In if) if it is equal to, true is returned to the IF parameter so that the contine in the previous parameter is executed, that is, the value is no longer in the B array. If B [II] is not equal to AAA during traversal execute return false to let the previous if execute the else {} operation, that is, continue to input the value 36 {37 return true to the B array; 38} 39} 40 return false; 41 42}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.