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
where to buy cipro online: ci pharm delivery – buy generic ciprofloxacin
Have a look at my blog; Find top-rated certified Daycares in your area
prednisone medicine PredniBest prednisone tablets india
cost of clomid prices: clomid on pharm – where to buy generic clomid now
Just finished my case with a great auto accident lawyer ! They were professional and really knew their stuff
вывод из запоя на дому санкт петербург вывод из запоя на дому санкт петербург .
The idea of personalizing user experience through web design is so relevant today! For more, visit rockland county webdesigner
спб нарколог вывод из запоя спб нарколог вывод из запоя .
Купить диплом о среднем полном образовании, в чем подвох и как избежать обмана?
Быстрое обучение и получение диплома магистра – возможно ли это?
Viagra uses technique No. Three — it eliminates the PDE that’s decomposing the cGMP, so cGMP builds up within the penis and has
a larger effect on the artery walls. Viagra/sildenafil is a
‘PDE5 inhibitor‘, but also impacts different PDE isozymes, resembling
PDE6 (an enzyme within the retina) which can result in visible disturbance.
They are often harmful when you’ve got sure underlying health conditions.
Dr. Maree Corkeron researched how drug interactions can have an effect on well being and reported
the findings within the Medical Journal of Australia 1.
The warnings for Valium and Viagra are very related.
They will overview your info and see whether one other therapy may match higher.
Some Medicare Part C and Part D plans might cover the price of some versions
of generic ED medications. It’s doubtless protected to take these medications together.
Then, it’s up to you to assess if they are strong enough to detract from the
advantages of taking Viagra Connect. Search and replace over
your complete site (the result are a gazillion modifications which could be reverted like peculiar changes).
darknet drug store dark web search engines tor darknet
вывод из запоя на дому санкт-петербург вывод из запоя на дому санкт-петербург .
7 Things You’ve Never Known About Mesothelioma Not Caused By Asbestos mesothelioma lawsuit
Hello, i think that i saw you visited my site thus i came
to “return the favor”.I’m trying to find things to improve my web site!I suppose its ok to
use a few of your ideas!!
This guide will definitely assist many homeowners prevent pricey errors regarding their roofing systems !! # anykeyword # roof flashing
May I simply just say what a comfort to find
an individual who genuinely understands what they’re discussing online.
You definitely realize how to bring a problem to light and make it important.
More and more people ought to read this and understand this side of the story.
I was surprised that you’re not more popular because you most certainly have
the gift.
вывод из запоя на дому санкт петербург вывод из запоя на дому санкт петербург .
can i purchase generic clomid pill: how to get cheap clomid tablets – can i get generic clomid without a prescription
вывод из запоя в санкт петербурге вывод из запоя в санкт петербурге .
Интересные статьи о займах – https://www.apsny.ge/2021/other/1640192443.php
Игровые автоматы Аркада приносят не только
удовольствие, но и выигрыши!
arkada
prednisone brand name india: order prednisone with mastercard debit – purchase prednisone from india
where can i buy cipro online: buy generic ciprofloxacin – where to buy cipro online
What Is SEO Software Tips To Relax Your Daily
Life What Is SEO Software Trick That Every Person Must Know seo software; Kristine,
вывод из запоя на дому вывод из запоя на дому .
where to get generic clomid: generic clomid without prescription – can you buy clomid without prescription
https://www.wpsue.com WPS Office: 一站式办公服务平台: 新升级,无广告,AI办公更高效. 立即下载. 登录使用. WPS 365: 面向组织和企业的WPS 365: 一站式AI办公,生产力即刻起飞. 了解更多. 咨询,记忆体占用低,体积轻运行快. 将文字、表格、演示、PDF等融合为一个组件。
you’re really a excellent webmaster. The website loading pace
is incredible. It sort of feels that you are doing any distinctive trick.
Furthermore, The contents are masterpiece. you have performed a excellent process in this subject!
With havin so much content and articles do you ever run into any
issues of plagorism or copyright infringement?
My website has a lot of exclusive content I’ve either created myself or
outsourced but it looks like a lot of it is popping
it up all over the web without my agreement. Do you know any techniques to help protect against content
from being stolen? I’d certainly appreciate it.