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
5 Clarifications On Auto Accident Claims Attorney For car accident injury
amoxicillin script: generic amoxicillin over the counter – amoxicillin 500 mg purchase without prescription
Medication information. Long-Term Effects.
can i order rizatriptan without prescription
Everything trends of medicines. Get information here.
Authority link building is actually critical for boosting your website’s integrity and search engine rankings buy backlinks
The future belongs to those who can think critically, adapt quickly, and solve complex problems Ρομποτική για παιδιά
https://clomidonpharm.com/# how to buy generic clomid without rx
African Grey Parrot Tools To Ease Your Daily Life African Grey
Parrot Trick That Should Be Used By Everyone Learn african grey parrot
вывод из запоя в клинике спб вывод из запоя в клинике спб .
where can you get amoxicillin: amoxicillin without a prescription – amoxicillin 500 mg purchase without prescription
amoxicillin 500 mg cost: generic amoxil 500 mg – amoxicillin no prescipion
Hey I know this is off topic but I was wondering if you knew of any
widgets I could add to my blog that automatically tweet my newest twitter updates.
I’ve been looking for a plug-in like this for quite some time and
was hoping maybe you would have some experience with something like this.
Please let me know if you run into anything.
I truly enjoy reading your blog and I look forward to your new updates.
выведение из запоя на дому спб выведение из запоя на дому спб .
Аттестат 11 класса купить официально с упрощенным обучением в Москве
If you are going for most excellent contents like myself, simply visit this web page everyday since it presents feature contents, thanks
Have a look at my webpage: what is alpha bites
prednisone 60 mg: PredniBest – can you buy prednisone over the counter
WOW just what I was looking for. Came here by searching for tiktok beğeni hilesi
I’m gone to inform my little brother, that he should also visit this web site on regular basis to obtain updated from most up-to-date news.
Как получить диплом стоматолога быстро и официально
Интересные статьи о займах – https://www.r-nk.com/sravni-ru-osobennosti-vybora-kreditora.html
I wish I had known about the importance of a best personal injury attorney sooner
darknet market list dark web market dark web sites
вывод из запоя в санкт-петербурге [url=belbeer.borda.ru/?1-6-0-00000780-000-0-0-1730825410]вывод из запоя в санкт-петербурге[/url] .
Just had my first experience in an old-school barbershop—it was fantastic! Explore that vibe further at barber shop θεσσαλονικη
where to buy amoxicillin 500mg without prescription Amox Star where can you buy amoxicillin over the counter
Aw, this was a really nice post. Taking the time and actual effort to make a great article…
but what can I say… I procrastinate a whole lot and never
seem to get nearly anything done.
Very great post. I simply stumbled upon your blog and wanted
to say that I have really loved browsing your weblog posts.
After all I’ll be subscribing on your feed and I am hoping you write
again soon!
my site … alpha bites gummies
This post is really a nice one it helps new internet visitors,
who are wishing for blogging.
10 No-Fuss Methods For Figuring Out Your SEO Tools seo powersuite date ranges
for reports (Dominic)
cordarone blood glucose levels nexterone vs cordarone cordarone pronunciation key
cost of cordarone without insurance lements cordarone cordarone pacerone side effects
cost generic cordarone pills
cordarone blood glucose levels cordarone 200 mg canada fortress supplements cordarone uses
cordarone maintenance dose cordarone 100 mg side effects cordarone effetti collaterali
WOW just what I was searching for. Came here by searching for sex indo viral