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
1win официальный сайт вход 1win официальный сайт вход .
1 вин официальный сайт вход http://fabc.com.kg/ .
canadian pharmacy no prescription needed http://xxlmexicanpharm.com/# mexico drug stores pharmacies
Best online pharmacy: Online pharmacy USA – Online pharmacy USA
tor market https://github.com/darknetwebsitesgflpx/darknetwebsites – onion market
порно гинеколог порно гинеколог .
dark market https://github.com/darkwebmarketslinks/darkwebmarkets – deep web drug markets dark market
easy canadian pharm: canada rx pharmacy – canadian pharmacy mall
1win 1win .
Beauty Salon Services HiOP
осмотр гинеколога порно http://ginekolog-rukoeb1.ru .
canadian pharmacy tampa: legit canadian pharmacy – pharmacy in canada
порно у гинеколога порно у гинеколога .
darknet drug market https://github.com/darkmarketlinkp22jr/darkmarketlink – darknet market lists
Paragraph writing is also a fun, if you be acquainted with afterward you
can write if not it is difficult to write.
Online pharmacy USA: Best online pharmacy – cheapest pharmacy for prescriptions without insurance
осмотр гинеколога порно http://ginekolog-rukoeb1.ru .
pharmacy online 365 discount code http://easycanadianpharm.com/# canadian discount pharmacy
осмотр гинеколога порно ginekolog-rukoeb1.ru .
May I simply just say what a comfort to find someone that
truly knows what they are talking about online. You actually understand how to bring a problem
to light and make it important. More and more people really need to read
this and understand this side of the story.
I can’t believe you are not more popular because you certainly possess the
gift.
That is a good tip particularly to those new to the blogosphere.
Simple but very precise info… Thanks for sharing this
one. A must read post!
1Win crash-game Lucky Jet
1 win казино [url=https://www.fabc.com.kg]1 win казино[/url] .
Привет. Подскажите, где найтиразные статьи о кредитах? Сейчас читаю – https://credit-help32.ru
Reasons Why Online Casinos Are Becoming a Worldwide Trend
Internet-based gambling hubs have reshaped the gambling landscape, providing an unmatched level of comfort and range that physical establishments fall short of. Over time, a large audience globally have welcomed the fun of online gaming in light of its availability, engaging traits, and progressively larger range of offerings.
One of the main appeals of internet-based platforms is the vast array of entertainment options ready to play. Whether you enjoy engaging with old-school slots, diving into narrative-rich video slots, or strategizing in strategy-based games like Blackjack, virtual venues offer infinite choices. Several sites furthermore feature live gaming streams, giving you the chance you to interact with human game hosts and co-players, all while experiencing the immersive feel of a traditional gambling venue without leaving your home.
If you’re a beginner with the world of internet-based gaming or seek to explore proven options, why not engage with our active gaming forum? It’s a space where enthusiasts share tips, assisting you to maximize your gaming journey. Join the connections and learn more now: bet on red
Apart from the game range, digital casino services thrive in seamless entry.
1win онлайн http://fabc.com.kg .
I’m not sure why but this web site is loading very slow for me.
Is anyone else having this issue or is it a issue on my end?
I’ll check back later on and see if the problem still exists.
20 Fun Informational Facts About Recover Points On Your
Driving License permis b1 (Lola)
Mega India Pharm: Mega India Pharm – Mega India Pharm
порно гинеколог порно гинеколог .