JS 依照元素出現數量排序
同樣是最近遇到的狀況,需要利用陣列內元素出現的數量進行排序,以下為範例程式:
var array = ["1", "2", "4", "5", "2", "4", "2", "3"]; var str = array.toString(); var filter = []; var result = []; document.write("原始陣列:" + array + "<br>"); var get = function (str, tar, arr, tmp) { if (str.indexOf(tar) >= 0) { tmp = str.slice(str.indexOf(tar) + 1); arr.push(tar); get(tmp, tar, arr, tmp); } return arr; } for (i in array) { var elm = []; var tmp; var fstr = filter.join(); if (fstr.indexOf(array[i]) >= 0) { continue; } else { var tmp_arr = get(str, array[i], elm, tmp); result.push(tmp_arr.length + ':' + tmp_arr[0]); filter.push(array[i]); } } result.sort(); result.reverse(); //按照出現次數排序,不刪除重複元素 var finishArray = []; for (index in result) { var show = result[index].split(':'); for (i = 0; i < show[0]; i++) { finishArray.push(show[1]); } } document.write("按出現次數排序,不刪除重複元素:" + finishArray + "<br>"); //按照出現次數排序,刪除重複元素 var finishArray = []; for (index in result) { var show = result[index].split(':'); finishArray.push(show[1]); } document.write("按出現次數排序,刪除重複元素:" + finishArray + "<br>");
輸出結果:
原始陣列:1,2,4,5,2,4,2,3 按出現次數排序,不刪除重複元素:2,2,2,4,4,5,3,1 按出現次數排序,刪除重複元素:2,4,5,3,1
They have items to market or solutions to supply.
Also visit my site: nib not working
In this instance, the life insurance policy firm’s money.
Here is my site; nib foundation nz
Viagra sans ordonnance livraison 48h: Sildenafil Viagra – Acheter Sildenafil 100mg sans ordonnance
USP human growth hormonal agent (somatropin).
Take a look at my web page how much does vigabatrin cost
There are numerous locations to locate t-shirt layouts.
Feel free to visit my webpage :: Bookmarks
pharmacie en ligne france pas cher: pharmacie en ligne pas cher – acheter mГ©dicament en ligne sans ordonnance
Then work together individually to create a custom-made t-shirt.
Feel free to visit my web-site; Bookmarks
Developers from worldwide pitch you ideas.
My web blog t shirt design template photoshop
What is New U Life SOMADERM Transdermal Gel.
my webpage – sump pump repair near me
High quality tee shirts and superb print quality.
Visit my blog: T Shirt Design Ideas Logo
XYGENYX, a licensing firm for FDA-registered products.
Here is my site … Is foundation necessary in makeup
What is New U Life SOMADERM Transdermal Gel.
My site Are night Vision goggles illegal in canada
NewULife Ranks. Welcome to my NewUlife Evaluation.
My web site How Much Does Vigabatrin cost
The larger Slim battery, wonderful for longer runtimes.
Take a look at my blog post :: Bookmarks
They have items How to say vigabatrin offer or solutions to supply.
Real HGH Benefits (NewULife Hgh Gel Not Evaluated Yet).
Visit my blog post; Bookmarks
They have items to sell or services to use.
Take a look at my website … nib not working
The Choices Are Yours With Private Education Loan Consolidation 청년 대출
10 Things We All Love About Situs Togel Dan Slot Terpercaya situs togel terpercaya (Florine)
XYGENYX, a licensing firm for FDA-registered items.
Feel free to visit my web site: Bookmarks
Then team up individually to develop a customized t-shirt.
Also visit my web blog: Bookmarks
Meilleur Viagra sans ordonnance 24h: Viagra sans ordonnance 24h – Viagra 100 mg sans ordonnance
https://pharmaciepascher.pro/# pharmacie en ligne livraison europe
60+ stunning instances of geometric designs.
Also visit my webpage: t shirt design template pdf
Then work together individually to develop a customized tee t shirt design app download.
Genuine HGH Benefits (NewULife Hgh Gel Not Tested Yet).
My page … can a foundation apply for grants
An artificial USP human development hormone (somatropin).
Also visit my homepage do you have to wear foundation With eye makeup
Typeography TShirt Style Example Bootstrapping.
My site :: t shirt design template pdf
In this situation, the life insurance policy company’s money.
My blog – Bookmarks
Let me show you in my review of NewULife.
My blog nib foundation nz