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
Официальное получение диплома техникума с упрощенным обучением в Москве
Вопросы и ответы: можно ли быстро купить диплом старого образца?
locowin offizielle website
fantastic issues altogether, you just received a new reader.
What may you suggest in regards to your publish that you made a few days
in the past? Any positive?
Легальная покупка школьного аттестата с упрощенной программой обучения
Amazing! This blog looks just like my old one!
It’s on a totally different subject but it has pretty much the same layout and design. Superb choice of colors!
16 Facebook Pages That You Must Follow For Which Coffee Machines Are Best Marketers Best Cappuccino Machine Uk – Minecraftcommand.Science,
Узнайте, как безопасно купить диплом о высшем образовании
If you are going for most excellent contents
like myself, just go to see this website every day since it offers feature contents, thanks
Thanks on your marvelous posting! I seriously enjoyed
reading it, you’re a great author.I will make certain to bookmark your blog and will come back from now on.
I want to encourage you to continue your great writing, have
a nice holiday weekend!
Парадокс, но купить диплом кандидата наук оказалось не так и сложно
I like the valuable information you provide in your
articles. I’ll bookmark your blog and check again here frequently.
I’m quite sure I’ll learn lots of new stuff right here!
Good luck for the next!
This is a topic which is near to my heart… Take care!
Exactly where are your contact details though?
Who’s The Top Expert In The World On Misted Double Glazed Units Cost?
can you repair misted double glazing (ahmad-poole.Hubstack.net)
Всё, что нужно знать о покупке аттестата о среднем образовании
en cok kazand?ran slot oyunlar?: en kazancl? slot oyunlar? – az parayla cok kazandiran slot oyunlar?
https://denemebonusuverensiteler.top/# deneme bonusu veren siteler 2024
deneme bonusu veren siteler betturkey betturkey.com
Как приобрести аттестат о среднем образовании в Москве и других городах
monstaluck.mn.co/posts/70000425
I enjoy what you guys are up too. Such clever work and coverage!
Keep up the amazing works guys I’ve added you guys to
blogroll.
кожзам для мебели https://www.iskusstvennaya-kozha-dlya-mebeli-kupit.ru .
согласование перепланировки квартиры цена согласование перепланировки квартиры цена .
9 . What Your Parents Taught You About Daftar Akun Togel Resmi daftar akun togel resmi (Karin)
Узнайте стоимость диплома высшего и среднего образования и процесс получения
deneme bonusu veren siteler https://denemebonusuverensiteler.top/# deneme bonusu veren siteler mycbet.com
http://denemebonusuverensiteler.top/# deneme bonusu veren siteler yeni
deneme bonusu veren yeni siteler
deneme bonusu veren siteler mycbet.com https://ultrabet-tr.online/# ultrabet yeni giris 1125
The Three Greatest Moments In Mesothelioma Attorney Texas History Mesothelioma Lawsuit
3 Common Reasons Why Your Glass Replacement Isn’t Working (And How To Fix It) house glass replacement
Как приобрести аттестат о среднем образовании в Москве и других городах
zpu-journal.ru/forum/view_profile.php?UID=314175
Medicament information for patients. What side effects can this medication cause?
generic amoxicillin over the counter
Actual what you want to know about meds. Get information now.