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
dark web market https://github.com/darkmarketlinkp22jr/darkmarketlink – tor marketplace
1вин 1вин .
tor markets links https://github.com/darknetmarketslinks/darknetmarketlinks – darkmarket drug markets dark web
dark market list https://github.com/darkwebmarketslinks/darkwebmarkets – dark web market darknet market links
Привет. Может кто знает, где найтиразные статьи о кредитах? Пока нашел – https://vsekredity-tmn.ru
Приветствую. Может кто знает, где почитатьразные блоги о займах? Пока нашел – 7sevenauto.ru
deep web search https://github.com/darkwebwebsites/darkwebwebsites – deep web drug store darknet drugs
darknet links https://github.com/darknetmarketslinks/darknetmarketlinks – darknet drug store darkmarkets
discount drug pharmacy: drug mart – no prescription required pharmacy
секс с гинекологом секс с гинекологом .
A The Complete Guide To Buy Driving License A1 From Start To Finish kup prawo jazdy kat a
Oh my goodness! Incredible article dude! Thanks, However I am going through problems with your RSS.
I don’t know the reason why I cannot subscribe to it.
Is there anybody having the same RSS issues? Anybody who knows
the answer can you kindly respond? Thanks!!
мультики ххх https://multiki-rukoeb1.ru .
bitcoin dark web https://github.com/darkmarketlinkp22jr/darkmarketlink – dark web drug marketplace
официальный сайт 1win http://www.fabc.com.kg .
online pharmacy delivery usa online pharmacy delivery usa Best online pharmacy
darknet drug links https://github.com/darknetwebsitesgflpx/darknetwebsites – dark web link
dark web market links https://github.com/darkmarketlinkp22jr/darkmarketlink – tor markets links
порно с гинекологом порно с гинекологом .
официальный сайт 1win http://bbcc.com.kg .
cheapest pharmacy to fill prescriptions without insurance https://familypharmacy.company/# family pharmacy
1 win регистрация https://fabc.com.kg .
Good day I am so happy I found your site, I really found you by error, while I was looking on Google for something
else, Anyhow I am here now and would just like to say thanks a lot for a marvelous post and a all round exciting blog (I also love the theme/design),
I don’t have time to go through it all at the minute but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to
read a great deal more, Please do keep up the great work.
Viagra en ligne, ordre en ligne viagra, Conferencedesbatonniers. Meilleur ordonnance, 50mg en ligne escompte Canada acheter cialis pilule de. Pfizer cialis achat meilleur pharmacie cipla.Achat en ligne prescription du. Retrouvez les services Click Collect et Ordonnance en ligne de votre. Acheter viagra en ligne, viagra de achat Canada, Universal Leonardo. https://eurogeneriqueetfrance.com/imurek/ Acheter Imurek Pharmacie
thecanadianpharmacy easy canadian pharm easy canadian pharm
darknet market list https://github.com/darkwebmarketslinks/darkwebmarkets – dark web link dark market url
What Makes Online Casinos Have Become a Worldwide Trend
Online casinos have reshaped the casino gaming market, delivering an unmatched level of convenience and range that traditional establishments fall short of. Over the past decade, a vast number of enthusiasts worldwide have adopted the pleasure of virtual casinos in light of its accessibility, engaging traits, and constantly growing selection of games.
One of the main appeals of digital gambling sites is the unparalleled range of titles provided. Whether you prefer interacting with old-school one-armed bandits, immersing yourself in story-driven visual slot games, or mastering skills in classic casino games like Roulette, online platforms feature countless options. Several sites furthermore introduce live gaming streams, giving you the chance you to communicate with actual dealers and fellow gamblers, all while taking in the lifelike ambiance of a brick-and-mortar establishment right at home.
If you’re unfamiliar with the world of digital casinos or hope to learn about proven options, why not sign up for our lively interactive platform? It’s a destination where enthusiasts exchange insights, guiding you to enhance your gaming journey. Join the community and start your journey now: 22bet recensioni
Besides the wide selection, virtual gambling platforms shine accessibility.
darkmarket https://github.com/darkmarketlinkp22jr/darkmarketlink – bitcoin dark web
You can definitely see your skills in the work you write.
The arena hopes for even more passionate writers such as you who aren’t afraid to mention how they believe.
Always follow your heart.
http://www.duc-sozvezdie.ru – Перейти на сайт производителя кухонь.