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
deep web drug url darknet market https://darknetmarketstore.com/ – darknet sites
where can i get prednisone over the counter: prednisone ray pharm – how can i order prednisone
Узнайте, как приобрести диплом о высшем образовании без рисков
cost of prednisone 40 mg: prednisone – online order prednisone 10mg
Pill effects explained. Contraindications explained here.
buy finasteride no prescription
Short-term impacts described. Drug impacts explained.
There are various tools and websites that affirmation to
allow users to view private Instagram profiles,
but it’s important to retrieve these past caution. Many
of these tools can be unreliable, may require personal information, or could violate
Instagram’s terms of service. Additionally, using such tools
can compromise your own security or guide to scams.
The safest and most ethical way to view a private instagram viewer profile is to
send a follow demand directly to the user. Always prioritize privacy and adulation in your online interactions.
buy dapoxetine online: Priligy tablets – cheap priligy
Fabulous, what a website it is! This website presents
valuable data to us, keep it up.
amoxicillin 500mg over the counter: com pharm – buy amoxicillin 500mg
{
Feel free to visit my web site 1xbet
priligy maxpharm: cheap priligy – Priligy tablets
Всё, что нужно знать о покупке аттестата о среднем образовании без рисков
priligy: dapoxetine price – priligy maxpharm
Hi there i am kavin, its my first time to commenting anyplace,
when i read this article i thought i could also create comment due
to this brilliant post.
Быстрое обучение и получение диплома магистра – возможно ли это?
I simply could not depart your website prior to suggesting that I actually loved the usual info a person supply on your guests?
Is gonna be back steadily to check out new posts
Now I am going to do my breakfast, afterward having my breakfast coming
over again to read additional news.
Как приобрести диплом техникума с минимальными рисками
amoxicillin order online: buy amoxil online – amoxicillin 500 mg tablet price
prednisone 10mg tabs: prednisone – prednisone uk over the counter
cost generic celebrex without dr prescription
Cool blog! Is your theme custom made or did you download it from somewhere?
A theme like yours with a few simple adjustements would really make my blog jump
out. Please let me know where you got your theme.
Bless you
Hello friends, good article and nice arguments commented at this place, I am really enjoying by these.
dark web search engine dark websites https://darknetmarketstore.com/ – darknet links
Do you mind if I quote a couple of your posts as long as
I provide credit and sources back to your site?
My blog is in the exact same niche as yours and my users would genuinely benefit from a lot of the information you provide here.
Please let me know if this okay with you.
Appreciate it!
amoxicillin buy no prescription: amoxil com pharm – amoxicillin 1000 mg capsule
This is really interesting, You are a very skilled blogger.
I’ve joined your feed and look forward to seeking more
of your wonderful post. Also, I have shared your website in my social networks!
There are various tools and websites that claim to permit
users to view private instagram viewer Instagram profiles, but it’s important to log on these
subsequently caution. Many of these tools can be unreliable, may require personal information, or could violate Instagram’s terms of service.
Additionally, using such tools can compromise your own security or lead
to scams. The safest and most ethical artifice to view a private profile is
to send a follow demand directly to the user. Always prioritize privacy and esteem in your online
interactions.
how to purchase prednisone online: cheap prednisone – prednisone pharmacy
Hi there, after reading this amazing article i am
as well delighted to share my know-how here with colleagues.