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
denemebonusuverensiteler.top https://ultrabet-tr.online/# ultrabet
See What Folding Treadmill Incline Tricks The Celebs Are Using folding treadmill incline – https://maps.google.hr/url?q=https://telegra.ph/20-insightful-quotes-on-treadmill-Folding-03-07,
Hi there would you mind letting me know which
webhost you’re utilizing? I’ve loaded your blog in 3 completely different internet browsers and I must say this blog loads a lot faster then most.
Can you recommend a good web hosting provider at a honest
price? Thanks, I appreciate it!
Вопросы и ответы: можно ли быстро купить диплом старого образца?
politikforum.ru/member.php?u=13385920
Car Boot Mobility Scooters Tips To Relax Your Daily Life Car Boot Mobility Scooters Trick That Every Person Must Be
Able To boot mobility scooters
deneme bonusu veren siteler denemebonusu2026.com https://slot-tr.online/# en cok kazand?ran slot oyunlar?
I blog quite often and I truly appreciate your
content. Your article has really peaked my interest. I
will take a note of your blog and keep checking for new details about once a week.
I opted in for your RSS feed too.
Казахстанский VPS хостинг для стабильной работы сайта дешевый vps в казахстане
Medicine information leaflet. Generic Name.
lisinopril 40 mg generic
Some information about medicament. Get here.
deneme bonusu veren yeni siteler: deneme bonusu veren siteler – deneme bonusu veren siteler denemebonusu2026.com
Полезная информация как официально купить диплом о высшем образовании
cslregister.com/forum/member.php?u=6225
deneme bonusu veren siteler betturkey betturkey.com: deneme bonusu veren siteler – deneme bonusu veren siteler yeni
The Infrequently Known Benefits To Private Assessment For
ADHD adhd Assessment private cost
диплом кандидата наук нового образца купить many-diplom77.ru .
5 Must-Know-How-To Toto Website Official Methods To 2024 토토사이트
추천 (Demi)
ultrabet tr online: ultrabet yeni giris 1125 – ultrabet giris
Remarkable things here. I’m very glad to see your post. Thank you so much and I’m
having a look ahead to touch you. Will you kindly drop me a
mail?
Paragraph writing is also a fun, if you be acquainted
with afterward you can write if not it is complicated to write.
deneme bonusu veren siteler mycbet.com: deneme bonusu veren yeni siteler – deneme bonusu veren siteler denemebonusu2026.com
I was curious if you ever considered changing the page layout of your site?
Its very well written; I love what youve got to say. But maybe you could a little more in the way of content so people could connect
with it better. Youve got an awful lot of text for only
having one or two images. Maybe you could space it out better?
Тут можно преобрести сейф противопожарный купить сейф огнестойкий в москве
купить диплом проф переподготовка many-diplom77.ru .
Woah! I’m really enjoying the template/theme of this website.
It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance” between user friendliness
and visual appeal. I must say you’ve done a superb job with
this. Also, the blog loads super quick for me on Firefox.
Superb Blog!
I’ve been browsing online more than three hours nowadays, yet I never found any fascinating article like
yours. It is beautiful value sufficient for me. Personally, if all site owners
and bloggers made just right content as you did, the internet
will likely be much more helpful than ever before.
We are tied directly into the sate’s renewal database which allows us to process your request almost instantly
This is very interesting, You’re a very skilled blogger.
I’ve joined your feed and look forward to seeking more of your fantastic post.
Also, I’ve shared your website in my social networks!
https://w9.mbahsemar.org/
Link exchange is nothing else however it is only
placing the other person’s website link on your page at proper place and
other person will also do same for you.
slot oyunlar? az parayla cok kazandiran slot oyunlar? az parayla cok kazandiran slot oyunlar?
Можно ли купить аттестат о среднем образовании, основные моменты и вопросы
Hello to all, how is everything, I think every one is getting more from this web page,
and your views are fastidious in favor of new viewers.