Two-part linear array de-weight

Source: Internet
Author: User

We said yesterday two times the method of linear search, this time we will say two times linear array de-heavy usage.

  

//first set up an array    vararr = [1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 5, 5, 6, 7, 8, 9, 0, 0, 3, 4, 5]; //Let's wrap up a function to calculate the calculation of the array's weight.    functionFindinarr (arr,n) {//Comparison of data         for(vari = 0; i < arr.length; i++){            //do not see that the IF statement does not think so, in fact, it is possible            if(Arr[i] = = N)return true; }            return false; }        //encapsulates a function of a two-point de-weight    functionRemovedup (arr, S, e) {//Let's start by judging if it's wrong .        if(S >e) {            return false; }Else if(s = =e) {            //If there is only one data in the array, return a number.            return[Arr[s]]; }        //Calculate intermediate Values        varc = Math.floor ((s + e)/2); //divide the data into two        varL =Removedup (arr, S, c); varr = Removedup (arr, C + 1, E); //Start Cycle comparison         for(vari = 0; i < r.length; i++){            if(!Findinarr (L,r[i]))            {L.push (r[i]); }        }        //finally returns the computed array        returnl; }    //send results to the consoleConsole.log (Removedup (arr, 0, arr.length-1));

So that we can do the deduplication step in the array, with two times linear is a lot of data can be quickly analyzed. If you are interested, you can try it.

Two-part linear array de-weight

Related Article

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.