Make the array without duplicates by recursion

Source: Internet
Author: User

Delete the same item in the array so that there are no duplicates in the array
The array's own method, splice (A, B), returns a new array after each use, so the recursive method must be used to remove the same items in the array, and if not, some items are ignored
For example, if recursion is not used, the output will be 1,2,3,4,5,6,7,1 it is obvious that the first and last items are the same and do not achieve the desired effect.
There is no problem with recursion, the output will be 1,2,3,4,5,6,7;

1 varARRZFS = [1,2,2,3,4,4,1,3,5,6,7,7,1,1,1,1,1];2(function()3 {4      for(vari = 0; i < arrzfs.length-1; i++)5     {6          for(varJ= i+1; J < Arrzfs.length; J + +)7         {8             if(Arrzfs[i] = =Arrzfs[j])9             {TenArrzfs.splice (j,1); OneArguments.callee ();//Call yourself A             } -         } -     } the })(); -(function() - { -      for(vari = 0; i < arrzfs.length; i++) +     { - Cc.log (Arrzfs[i]); +     } A})();

Make the array without duplicates by recursion

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.