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
https://slotsiteleri.bid/# slot siteleri guvenilir
What’s up, this weekend is pleasant in support of me, because this point in time
i am reading this enormous informative paragraph here at my home.
Everything is very open with a precise clarification of the issues.
It was truly informative. Your website is extremely helpful.
Thanks for sharing!
en iyi slot siteleri 2024: deneme veren slot siteleri – en yeni slot siteleri
Pills information. Brand names.
buying pulmicort prices
Some trends of meds. Get information now.
Good article. I will be facing some of these issues as well..
Also visit my homepage Ultra K9 Pro Reviews
my web site Daycare Near Me By State (nowguru.com)
slot oyunlar? siteleri: en cok kazandiran slot siteleri – guvenilir slot siteleri 2024
Howdy! I could have sworn I’ve been to this website before but after checking through some
of the post I realized it’s new to me. Anyhow, I’m definitely glad I found it and I’ll be book-marking and checking
back frequently!
I’m curious to find out what blog system you are
utilizing? I’m having some minor security issues with my
latest blog and I’d like to find something more secure.
Do you have any solutions?
http://slotsiteleri.bid/# slot siteleri 2024
slot bahis siteleri: guvenilir slot siteleri – casino slot siteleri
What Is The Evolution Of Nissan Juke Key Replacement replacement Nissan key
Games – Which Will Be Easiest To Play 에볼루션 예측 프로그램
https://denemebonusuverensiteler.win/# deneme bonusu
Hi there, yeah this article is actually fastidious and I have learned
lot of things from it on the topic of blogging. thanks.
watch porn video
9 . What Your Parents Teach You About Outdoor U Shaped
Sectional outdoor U Shaped sectional
slot kumar siteleri: oyun siteleri slot – yasal slot siteleri
guvenilir slot siteleri 2024: bonus veren slot siteleri – slot oyunlar? siteleri
slot bahis siteleri: deneme veren slot siteleri – deneme bonusu veren siteler
http://slotsiteleri.bid/# en yeni slot siteleri
Here is my page Find top-rated certified Daycares in your area
Visit my web-site; Daycares popular listings
slot bahis siteleri: slot casino siteleri – guvenilir slot siteleri
http://slotsiteleri.bid/# canl? slot siteleri
הן המקום שבו אתה יכול להגשים את הפנטזיות שלך. המקום שבו כל הגברים מגשימים את הפנטזיות שלהם. הנערות היפות והסקסיות תמיד מחכות ולשאול שאלות. הן מגיעות בשביל לבלות עם גברים ולגרום לגברים להרגיש טוב. בשביל זה הן כאן, בשביל בילויים משותפים ומלאים Enjoy Tel Aviv sex with the most seductive liberated women
https://slotsiteleri.bid/# guvenilir slot siteleri 2024
guvenilir slot siteleri 2024: deneme veren slot siteleri – slot oyunlar? siteleri
Excellent goods from you, man. I’ve understand
your stuff previous to and you are just too excellent.
I actually like what you have acquired here, certainly like
what you’re saying and the way in which you say it.
You make it enjoyable and you still take care of to keep it smart.
I can not wait to read far more from you. This is really a terrific site.