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
how can i get valtrex online
Highly energetic article, I enjoyed that a lot.
Will there be a part 2?
Those that cut the wages of their employees remained in the minority at 5.2 per cent, said the Manpower Ministry. Among them, the magnitude of wage cuts was also smaller in 2022 than the preceding year. 토토힐
The Best Themed Slots Tips For Changing Your Life Real casino slots
how can i get zyloprim online
Drugs information for patients. Short-Term Effects.
where to buy fluoxetine price
Actual about pills. Read now.
Why Upvc Windows Repair Isn’t A Topic That People Are Interested In Upvc Windows Repair repair Upvc windows
https://www.diigo.com/item/note/a69lu/v9d8?k=a85964e34f0875d25964abb95af83442
Drug information sheet. What side effects can this medication cause?
where can i get cheap arimidex without a prescription
Best trends of medicament. Read information now.
продвижение сайтов в москве яндекс prodvizhenie-sajtov-v-moskve115.ru .
продвижение сайтов в москве в яндексе prodvizhenie-sajtov-v-moskve115.ru .
11 Creative Methods To Write About Popular Casino Slots online casino slots
продвижение сайтов в москве и московской области http://www.prodvizhenie-sajtov-v-moskve115.ru .
9 Things Your Parents Teach You About Psychiatrist Private Psychiatrist private
продвижение медицинских сайтов в москве prodvizhenie-sajtov-v-moskve115.ru .
What Is Asbestos Mesothelioma Lung Cancer’s History?
History Of Asbestos Mesothelioma Lung Cancer Mira
See What Can I Buy From A Uk Website Tricks
The Celebs Are Making Use Of can i buy From a uk website –
Rladusdn74.woobi.co.kr,
get generic lexapro without insurance
The Most Hilarious Complaints We’ve Received About Mesothelioma From Asbestos Belinda
Speak “Yes” To These 5 SEO Agency Pricing Tips
best Seo agency in london
Asbestos claims are complicated because they usually involve multiple jurisdictions.
Law firms that have experience processing asbestos
claim (https://account.sonora.id/login/c29ub3Jh==/aHR0cHM6Ly92YWxldGlub3dpa2kucmFjaW5nL3dpa2kvMjBfVGhpbmdzX1lvdV9TaG91bGRfS25vd19BYm91dF9Bc2Jlc3Rvc19NZXNvdGhlbGlvbWE) claims
on a national and state level are aware of the specific laws involved.
5 Reasons To Be An Online New Slots Online Shop And
5 Reasons Not To Reputable slots
whoah this weblog is wonderful i really like reading your posts.
Stay up the great work! You understand, lots of persons are searching around for this info, you can help them greatly.
I must thank you for the efforts you have put in penning
this blog. I am hoping to view the same high-grade content from you later on as well.
In truth, your creative writing abilities has motivated me to get my
own, personal site now 😉 https://www.freelegal.ch/index.php?title=Utilisateur:OTZRoman8552
We focus on small enterprise marketing.
Here iis my webpage … review of cosori
I love it when folks get together and share views. Great website,
keep it up!
20 Compact Electric Wheelchair Uk Websites Taking
The Internet By Storm top Rated electric wheelchairs
There Are A Few Reasons That People Can Succeed At The Online
Shop Industry Freestanding Dog Gate
Congress has approved a variety of incremental legislation plans, despite
the fact that Asbestos lawyer is still prohibited.
One of them proposed legislations, the Frank R.
20 Things You Must Be Educated About High Roller Slots Slot Games