1 <!DOCTYPE HTML>2 <HTMLLang= "en">3 <Head>4 <MetaCharSet= "UTF-8">5 <title>Go heavy</title>6 </Head>7 <Body>8 <Scripttype= "Text/javascript">9 /*array de-weight*/Ten functionQuchong (arr) { One varLen=arr.length; A Arr.sort (); - for(varI=Len-1; I>0; I--){ - if(Arr[i]==Arr[i-1]){ the Arr.splice (i,1); - } - } - returnarr; + } - vara= ["a","a","b",'b','C','C','a','D']; + varb=Quchong (a); A Console.log (b); at /*string de-weight*/ - functionquchongstr (str) { - vara=Str.match (/\s+/g);//equivalent to Str.split (/\s+/g)//\s whitespace character, \s non-whitespace character - A.sort (); - for(varI=A.length-1; I>0; I--){ - if(A[i]==A[i-1]){ in A.splice (i,1); - } to } + returnA.join (" "); - } the varStr=Quchongstr ("A a b a B e"); * Console.log (str); $ Panax Notoginseng </Script> - </Body> the </HTML>
JS implementation string de-weight, array to weight