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
try this web-site https://trusteewallet.org/
safe canadian pharmacy: canadian valley pharmacy – canadian pharmacies
777 PUB
1с бухгалтерия купить 1с бухгалтерия купить .
https://naveridbuy.blogspot.com/2024/11/blog-post_3.html
where to get cheap allopurinol without rx can i get generic allopurinol tablets where to get generic allopurinol tablets
can you get allopurinol without rx can you buy cheap allopurinol for sale where buy generic allopurinol tablets
order allopurinol without dr prescription
order cheap allopurinol online can i get cheap allopurinol without rx how can i get cheap allopurinol pills
can i buy cheap allopurinol pills where to get generic allopurinol without rx where can i get cheap allopurinol tablets
Best Indian pharmacy: Indian Cert Pharm – Indian pharmacy that ships to usa
https://candid-lion-dd3cm3.mystrikingly.com/blog/2024
Sleep Well Tips The Best Way To Get That Goodnight Sleep You’ve Always Wanted 밤문화
Slot Machine Strategy 포포인츠 바이 쉐라톤 명동 뷔페 에볼루션
buying prescription drugs in mexico online: Mexican Easy Pharm – п»їbest mexican online pharmacies
medicine in mexico pharmacies: Mexican Easy Pharm – Mexican Easy Pharm
official statement https://brd-wallet.io
canadian drug prices: 77 canadian pharmacy – canadian pharmacy reviews
The Most Pervasive Issues In Car Key Cutting Near Me key cut place near me
Oh my goodness! Incredible article dude! Thank you, However I am having issues with your RSS.
I don’t know why I cannot subscribe to it. Is there anyone else getting identical RSS problems?
Anyone that knows the solution will you kindly respond?
Thanks!!
вывод из запоя в стационаре вывод из запоя в стационаре .
You’ll Never Guess This Truck Lawyers Near Me’s Tricks
Truck Lawyers
Indian pharmacy that ships to usa: Indian pharmacy international shipping – Online pharmacy
https://truthful-tulip-dbgzhv.mystrikingly.com/blog/3151683cc90
I visited many sites however the audio feature for audio songs present at
this website is actually fabulous.
Mat6tube Truly enlightening articles or reviews right now
additional resources https://brd-wallet.io/
https://medium.com/@nsw5288/%EB%B9%84%EC%95%84%EA%B7%B8%EB%9D%BC-%EA%B5%AC%EB%A7%A4-%EC%86%8C%EC%85%9C-%EB%AF%B8%EB%94%94%EC%96%B4%EB%A5%BC-%ED%99%9C%EC%9A%A9%ED%95%9C-%EC%A0%95%EB%B3%B4-%EC%B0%BE%EA%B8%B0-41a0f6743e53
вывод из запоя воронеж вывод из запоя воронеж .
вывод из запоя воронеж вывод из запоя воронеж .
настройка 1с бухгалтерии цена настройка 1с бухгалтерии цена .
Hi there, its nice paragraph about media print, we all be familiar with
media is a fantastic source of data.
It’s actually a great and helpful piece of info.
I’m happy that you simply shared this useful information with us.
Please keep us informed like this. Thanks for sharing.
It’s difficult to find experienced people about this subject, however, you sound like
you know what you’re talking about! Thanks