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
Master the art of Pachinko and unlock new levels of fun with each strategic shot.
https://denemebonusuverensiteler.win/# deneme bonusu
With havin so much content and articles do you ever run into
any problems of plagorism or copyright infringement? My site has a lot of unique content I’ve either authored myself
or outsourced but it looks like a lot of it is popping it
up all over the internet without my agreement.
Do you know any techniques to help prevent content from being stolen? I’d certainly appreciate it.
my page :: the growth matrix.
Hello there, I discovered your website by means of Google at the
same time as searching for a similar topic, your web site got here up, it looks
good. I’ve bookmarked it in my google bookmarks.
Hi there, just became alert to your weblog via Google, and found that it is truly informative.
I am going to watch out for brussels. I’ll be grateful
if you happen to continue this in future. Lots of other people will probably
be benefited out of your writing. Cheers!
I uѕeԀ to Ƅe recommended tһis website ƅy
wway off myy cousin. I’m no longer certain ԝhether or not
tһis put up is writtеn by way of him as no one elѕе recognize suchh distinct ɑpproximately mʏ trouble.
You’re incredible! Thanks!
Ηere іs my web ⲣage toto 4d
Hi to all, how is everything, I think every one
is getting more from this website, and your views are fastidious in support of new visitors.
We are a group of volunteers and opening a new scheme in our community.
Your web site offered us with valuable information to work on. You’ve
done an impressive job and our entire community will be thankful to you.
Key Programmers: What No One Is Talking About cut and program Car key
casino slot siteleri: deneme bonusu veren siteler – casino slot siteleri
The Paralympic Games are an universal multi-sport event in the course of athletes with disabilities. Held alongside the Olympic Games, these games idiosyncrasy a diverse file of sports adapted to various abilities. They were established to provide opportunities in favour of athletes with corporeal and barmy impairments to vie at the highest status and evince their incredible talents https://www.paralympicgames2024.ru.
https://sweetbonanza.network/# pragmatic play sweet bonanza
order balloons for birthday with delivery https://helium-balloons-dubai.com
sapporo88
Ev Taşıma | Ev taşıma sırasında karşılaşılan zorlukları minimize etmek için verilen ipuçları çok faydalı. Kozcuoğlu Ev Taşıma olarak, müşterilerimize bu süreçte profesyonel destek sağlıyoruz.
Как приобрести аттестат о среднем образовании в Москве и других городах
Thanks for sharing your thoughts on ссылка
на омг омг fb. Regards
slot oyunlar? siteleri: deneme bonusu veren slot siteleri – slot oyun siteleri
slot siteleri: slot siteleri 2024 – deneme veren slot siteleri
certainly like your website but you need to check the spelling on quite a few of your posts.
Many of them are rife with spelling problems and I in finding it
very bothersome to tell the truth then again I’ll surely come again again. https://Starfielduniverse.com/index.php?title=User:VenusFellows
casino slot siteleri: yasal slot siteleri – slot oyunlar? siteleri
It’s in point of fact a great and useful piece of information.
I’m satisfied that you just shared this useful information with us.
Please stay us up to date like this. Thanks for sharing.
Feel free to visit my site – billionaire brain wave reviews
Evden Eve Nakliyat | Müşteri memnuniyetinin evden eve nakliyat hizmetlerinde ne kadar önemli olduğunu bu yazıda çok güzel anlatmışsınız. Kozcuoğlu Evden Eve Nakliyat olarak, bu ilkeyi her zaman ön planda tutuyoruz.
guvenilir slot siteleri 2024: slot kumar siteleri – yeni slot siteleri
en iyi slot siteleri 2024: bonus veren casino slot siteleri – en yeni slot siteleri
Operators provide transfer services from/to terminals
for stable customers. Free shuttle buses run from/to the terminals 24 hours a day,
long-iad parking long term, including holidays.
Feel free to visit my web-site https://iadlongtermparking.com/
slot siteleri: slot casino siteleri – bonus veren slot siteleri
Официальный телеграм SYKAAA предлагает новым игрокам бонус 325% в 4 этапа, за активное повышение аккаунта – игрок получает круглосуточную поддержку и участие в турнирах. Новых игроков привлекает не только бонус 100FS за регистрацию, но и дизайн зеркало sykaaa на сайте наглядное меню, которое позволяет в пару кликов найти нужный провайдер, выбрать слот или сделать депозит.
For most recent news you have to visit internet and on internet I found this website
as a most excellent site for most recent updates.
Feel free to visit my web page: webpage
en yeni slot siteleri: deneme bonusu veren siteler – deneme bonusu veren siteler
bonus veren casino slot siteleri: slot kumar siteleri – en iyi slot siteleri 2024