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
I will right away take hold of your rss feed as I can not to find your email
subscription hyperlink or e-newsletter service.
Do you have any? Kindly allow me recognise
in order that I may subscribe. Thanks.
I am really enjoying the theme/design of your blog.
Do you ever run into any web browser compatibility problems?
A handful of my blog readers have complained about my blog not working
correctly in Explorer but looks great in Safari.
Do you have any tips to help fix this problem?
Amazing! Its in fact amazing piece of writing, I have got much clear idea regarding from
this article.
вывод. из. запоя. на. дому. ростов. http://vyvod-iz-zapoya-rostov229.ru/ .
http://sweetbonanza25.com/# sweet bonanza yorumlar
вывод из запоя стационарно ростов https://vyvod-iz-zapoya-rostov228.ru .
Guide To Accident Injury Lawyers: The Intermediate Guide The Steps To Accident
Injury Lawyers accident injury lawyers [Constance]
How An Individual Avoid Charge Fees? 다바오 골프 호텔
https://casinositeleri25.com/# canl? casino siteleri
Had an excellent experience with my recent move thanks to the team at austin office movers
Great Stuff That Have Happened In Bars hiop
Erektil dysfunktion Apotek, Online Sex medicin fц r Mц n, Viagra. I stayed at the Apotek Hotel with my husband as part of our Iceland stay. Farmasiku, Apotik Online INDICA, Apotek Online, Toko Obat Alat. Viagra Apotek Online, Eliminate Refractory Period. Apotekmart, Apotek Online APK Download, Free Medical APP for. Download Apotekmart, Apotek Online apk 1.3 and all version history for Android. Pharmacy2U is the UKs leading NHS approved online pharmacy and also. Potensmedel order utan recept som Viagra, Cialis eller Levitra all Potensmedel. Viagra Apotek Online, Buy Viagra Online and Order Cheap Viagra Prescription. https://pillerbestalla.space/sildenafil/ Bestalla Sildenafil Billig
My partner and I stumbled over here by a different website
and thought I should check things out. I like what I see
so now i’m following you. Look forward to looking into your web page yet again.
нарколог на дом вывод из запоя ростов нарколог на дом вывод из запоя ростов .
Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to more added agreeable from you! However, how can we communicate?
Just stumbled upon some reviews for Tacoma Sandblasting Tacoma wood sandblasting
Hello excellent website! Does running a blog such as this
take a large amount of work? I have no knowledge of coding however I had been hoping
to start my own blog soon. Anyway, if you have any recommendations or tips for new blog owners please share.
I understand this is off subject nevertheless I just
wanted to ask. Thank you!
Appreciate the thorough write-up. Find more at office movers in san jose
Great job! Discover more at Ressources supplémentaires
2u6pty
наркология вывод из запоя ростов http://www.vyvod-iz-zapoya-rostov228.ru .
I liked this article. For additional info, visit Casinos avec les meilleurs paiements
penis enlargement
Hey! I just wanted to ask if you ever have any issues with hackers?
My last blog (wordpress) was hacked and I ended up
losing months of hard work due to no backup. Do you have any solutions to protect against hackers?
100 먹튀검증 먹튀사이트 목록 확인 커뮤니티 먹튀모음 토토사이트 메이저사이트
스포츠 미니게임 파워볼 꽁머니사이트
모든 사이트 먹튀검증을 시행하고 있으며, 가장 빠른 먹튀검증사이트입니다
먹튀모음은 먹튀에서 안전한 공식 보증업체를 추천해드리며, 부당한 일을 당하지
않게 체계적인 시스템으로 운영하고 있습니다
The Biggest Problem With Car Remote Key Repair And How To Fix It remote
key repair near me – Deanna,
Thanks for the great content. More at cremation services
вывод из запоя цена ростов вывод из запоя цена ростов .
With havin so much content and articles do you ever run into any issues of plagorism or copyright
infringement? My blog has a lot of unique content I’ve either authored myself or outsourced but
it appears a lot of it is popping it up all over the internet without
my authorization. Do you know any solutions to help reduce content from being stolen? I’d definitely appreciate it.
вывод из запоя дешево ростов-на-дону вывод из запоя дешево ростов-на-дону .