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
lgbt porn
проститутка натали новосибирске
I have been browsing online more than three hours today, yet I never found any interesting article like yours.
It is pretty worth enough for me. Personally, if all webmasters and bloggers made good content as you did, the net
will be much more useful than ever before.
вавада зеркало на сегодняшний день тг вавады
20 Car Diagnostics Near Me Uk Websites Taking The Internet By Storm diagnostic check (Wilburn)
It’s an remarkable article in favor of all the online
visitors; they will take benefit from it I am sure.
Hello there! I just would like to give you a huge thumbs up
for your great info you have here on this post. I’ll be returning to your web
site for more soon.
http://denemebonusuverensiteler.win/# bonus veren siteler
Ставки на спорт для ЛГБТ сообщества | Спортивные ставки для LGBTQ+ на 1xbet | Gay-friendly 1xbet: ставки с комфортом | Секреты успешных ставок на спорт для ЛГБТ на 1xbet | 1xbet: надёжные ставки для геев
porn gay in 1xbet https://1xbetcasinogayclub-ar.com/ .
10 Simple Steps To Start Your Own Replacement Mini Key Fob Business mini key replacement near Me
This is a topic that is near to my heart… Thank you!
Where are your contact details though?
Saved as a favorite, I love your web site!
Женские вечерние платья https://vechernie-platya-princess.ru купить в интернет каталоге с доставкой в Москве. Брендовые женские вечерние платья в наличии и на заказ.
http://sweetbonanza.network/# sweet bonanza mostbet
It’s in point of fact a great and helpful piece
of information. I am glad that you shared this helpful info with us.
Please stay us up to date like this. Thanks for sharing.
http://denemebonusuverensiteler.win/# deneme bonusu
guvenilir slot siteleri 2024: deneme veren slot siteleri – slot siteleri bonus veren
The 12 Worst Types Key For Mercedes Accounts You Follow On Twitter mercedes replacement key
Right away I am ready to do my breakfast, later than having my breakfast coming over again to read additional news.
untrustable
untrustable
Как избежать рисков при покупке диплома колледжа или ПТУ в России
myteana.ru/forums/index.php?autocom=gallery&req=si&img=5311
Hello, everything is going well here and ofcourse every one is sharing information, that’s truly good, keep up writing.
Guide To Lexus Key Replacement Uk: The Intermediate Guide For Lexus Key
Replacement Uk Lexus key Replacement uk
гостиницы с проститутками в новосибирске
15 Things To Give The Mesothelioma Law Firm Lover In Your Life Mesothelioma lawsuit
yeni slot siteleri: en guvenilir slot siteleri – slot siteleri bonus veren
Guide To Lexus Key Fob Price: The Intermediate Guide In Lexus Key
Fob Price Lexus key fob price
Excessive passion can distance to heat-related illnesses such as quicken forth and heatstroke. W populations embody the old fogies, unfledged children, and individuals with chronic illnesses https://excessiveheatawareness.ru/.
untrustable