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
What a material of un-ambiguity and preserveness of precious experience regarding unexpected emotions.
Купить диплом о среднем образовании в Москве и любом другом городе
We absolutely love your blog and find many of your
post’s to be precisely what I’m looking for. Do you
offer guest writers to write content in your case?
I wouldn’t mind writing a post or elaborating on many of the subjects you write regarding here.
Again, awesome weblog!
фабрика кухня – Прямая работа с фабрикой для создания качественной и стильной кухни.
Personal injuries can have long-lasting effects, both physically and emotionally—great insights available at Louisville car accident lawyer
I always spent my half an hour to read this weblog’s posts all the time along with a
mug of coffee.
Medication prescribing information. Drug Class.
generic tamoxifen without dr prescription
Actual information about pills. Read information here.
Hi there! Quick question that’s completely
off topic. Do you know how to make your site mobile friendly?
My website looks weird when browsing from my iphone.
I’m trying to find a template or plugin that might be able to fix this issue.
If you have any suggestions, please share. Cheers!
Look at my homepage; ทดลองเล่นสล็อต
After I initially commented I appear to have clicked on the -Notify me when new comments
are added- checkbox and now whenever a comment is added I get four emails with the same
comment. Perhaps there is an easy method you are able to remove me from that
service? Kudos!
Всё, что нужно знать о покупке аттестата о среднем образовании без рисков
It’s difficult to find experienced people on this topic, but you sound like you know what you’re
talking about! Thanks
ivermectin 3mg for lice: IverFast – ivermectin 3mg price
This is a topic that is close to my heart… Many thanks! Where are your contact details though?
Приветствую. Может кто знает, где найтиполезные блоги о недвижимости? Пока нашел – https://tesla12.ru
Wonderful blog! Do you have any recommendations for aspiring writers?
I’m planning to start my own blog soon but I’m a little lost on everything.
Would you recommend starting with a free platform like WordPress or go for a paid option? There are so
many options out there that I’m completely overwhelmed .. Any suggestions?
Kudos!
Actually no matter if someone doesn’t know afterward its up to other users that they will assist, so here it happens. https://gratisafhalen.be/author/merry67c358/
buy minocycline 100 mg otc buy Stromectol ivermectin 0.5% lotion
buy cytotec over the counter: cyt premium – purchase cytotec
Всем привет! Может кто знает, где почитатьполезные статьи о недвижимости? Пока нашел – https://tesla12.ru
drug markets onion darkweb marketplace darknet market
Всем привет! Подскажите, где найтиполезные статьи о недвижимости? Пока нашел – https://tesla12.ru
There are various tools and websites that claim to allow users to view private instagram viewer app Instagram
profiles, but it’s important to open these in the manner of 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 pretentiousness to view a private
profile is to send a follow request directly to the user.
Always prioritize privacy and admiration in your online interactions.
Сколько стоит диплом высшего и среднего образования и как его получить?
Как безопасно купить диплом колледжа или ПТУ в России, что важно знать
Как получить диплом техникума с упрощенным обучением в Москве официально
Узнайте, как безопасно купить диплом о высшем образовании
Как купить диплом о высшем образовании с минимальными рисками
you can look here https://todoprogramas.com
Nice post. I was checking constantly this blog
and I’m impressed! Extremely useful info particularly the last part :
) I care for such info a lot. I was seeking this particular information for a long
time. Thank you and good luck.
Приветствую. Может кто знает, где найтиразные блоги о недвижимости? Пока нашел – https://tesla12.ru