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
matadorbet giris: matadorbet – matadorbet giris
https://matadorbet.bid/# matadorbet giris
deneme bonusu veren yeni siteler
10 Quick Tips For Mesothelioma Legal Question mesothelioma law
firm (Kristie)
How Link Togel Has Changed My Life The Better link Togel Resmi
Deneme Bonusu Veren Siteler: guvenilir casino siteleri – guvenilir casino siteleri
Are men who use ivermectin for goats and have multiple orgasms?|
Thanks very interesting blog!
It’s nearly impossible to find experienced people for this topic, but
you seem like you know what you’re talking about!
Thanks
There is certainly a lot to know about this subject.
I like all of the points you have made.
With havin so much content do you ever run into any issues of plagorism or copyright infringement?
My site has a lot of unique content I’ve either authored myself or
outsourced but it seems a lot of it is popping it
up all over the internet without my authorization. Do you
know any ways to help reduce content from being ripped off?
I’d certainly appreciate it.
matadorbet: matadorbet – matadorbet
5 Must-Know-Practices Of Porsche Key Replacement Cost For 2023 porsche cayenne replacement key Cost
Thankfulness to my father who stated to me concerning this weblog, this website is truly amazing.
https://w4.livedrawnevada.life/
Hello there, just became aware of your blog through Google, and found that
it is really informative. I am going to watch out for brussels.
I will appreciate if you continue this in future.
Lots of people will be benefited from your writing. Cheers!
https://w6.hkmalamini.org/
deneme bonusu veren siteler 2024 http://casinositeleri.win/# Casino Siteleri
Normally I don’t read post on blogs, however I wish to
say that this write-up very compelled me to take a
look at and do so! Your writing taste has been amazed me.
Thank you, very great article.
I was suggested this blog via my cousin. I’m now not certain whether or not this post is written by means
of him as no one else know such precise approximately my difficulty.
You are incredible! Thank you!
http://w1.mistiktogel.cfd/
Покупка школьного аттестата с упрощенной программой: что важно знать
Тут можно преобрести сейф противопожарный сейф огнеупорный
always i used to read smaller posts that as well clear their motive,
and that is also happening with this piece of writing which I am reading at this place.
Triangle Billiards & Bar Stools
1471 Nisson Ꭱd, Tustin,
ⲤA 92780, United Ꮪtates
+17147715380
Pool Table Repairs
The 10 Scariest Things About Replacement
Key For Fiat 500 Replacement Key For Fiat 500 (Morphomics.Science)
deneme bonusu veren siteler yerliarama.org: deneme bonusu veren siteler yerliarama.org – deneme bonusu veren siteler betturkey
Thanks for sharing your thoughts on penipu. Regards
Everything You Need To Learn About Automatic Folding
Mobility Scooter Near Me autofold mobility scooter (Marcy)
This blog was… how do I say it? Relevant!! Finally I have found something that helped me.
Many thanks!
https://w3.rumuscb.buzz/
Everything is very open with a very clear explanation of the challenges.
It was definitely informative. Your site is very helpful.
Thanks for sharing!
https://w5.livemacau.buzz/
https://ultrabet-tr.online/# ultrabet guncel
deneme bonusu veren siteler yeni
I’d like to find out more? I’d like to find
out more details.
http://ultrabet-tr.online/# ultrabet giris
deneme bonusu veren yeni siteler