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
http://ciprofloxacin.tech/# ciprofloxacin
The Myths And Facts Behind Auto Accident Lawsuit auto Accident law firms
How To Find The Perfect Mesothelioma Settlement Online Asbestos legal
There’s certainly a great deal to find out about this topic.
I really like all of the points you’ve made.
buy cytotec pills: Misoprostol 200 mg buy online – purchase cytotec
http://finasteride.store/# order cheap propecia without dr prescription
order generic propecia pills: cost of cheap propecia pill – order propecia pills
The Most Worst Nightmare Concerning Double Glazed Repairs Near Me Get
Real repairing
15 Best Documentaries On Double Glazing Windows Leeds new
glazing leeds – Gilbert,
Your method of explaining the whole thing in this article is in fact pleasant, every one can simply be aware of it,
Thanks a lot https://solliart.com/pages/politique-de-livraison-et-retour
10 . Pinterest Account To Be Following Window Repair Door Repair (http://Spectr-Sb116.Ru)
The 10 Most Terrifying Things About Car Keys Cutting Near Me
car keys cutting Near me
Nine Things That Your Parent Teach You About Nissan Juke Key Fob Replacement Nissan Juke Key Fob Replacement
lexapro and tamoxifen should i take tamoxifen nolvadex price
The Three Greatest Moments In Mesothelioma Lawyer History mesothelioma legal
The 10 Scariest Things About CSGO Most Profitable Cases operation wildfire Case
ciprofloxacin 500 mg tablet price: cipro 500mg best prices – buy cipro online without prescription
наркологический центр алматы цены https://someblog.ru/
cipro 500mg best prices: ciprofloxacin 500 mg tablet price – antibiotics cipro
lisinopril 5 mg tablet price in india: lisinopril 20 mg online – lisinopril cheap brand
The 10 Most Terrifying Things About Medical Malpractice Attorneys medical malpractice attorneys – Sarah –
10 Signs To Watch For To Buy A Double Glazing Repairs Near Me double glazing Repairs near me
What’s The Current Job Market For Veleco Electric Scooter Professionals Like?
veleco
10 Things We Were Hate About ADHD Diagnosis Private UK adhd assessment private
[Jerri]
Tradicionālie fiziskie kazino ir joprojām pieejami
(Latvijā gan ar katru gadu arvien limitētākā daudzumā), taču nav tik aktuāli kā online versijas.
Nav brīnums, jo spēlēt tiešsaistē var jebkurā laikā un dienā, spēles būs pieejamas
vienmēr, kā arī nav jāgaida, kamēr atbrīvosies vieta pie galdi.
Papildus, kā vienu no labākām priekšrocībām pieminēsim arī bonusus, kuri ir pieejami tikai tiešsaistē.
Taču pastāv viena neērtība – plašs vietņu klāsts.
Lai ieteiktu saviem lasītajiem tikai labāko, mums par kazino ir jāzina viss.
Tieši tāpēc mēs izveidojām komandu no izciliem industrijas ekspertiem,
kas apkopo pieejamo informāciju internetā,
analizē spēļu vietnes, veido spēlētāja kontus
un komunicē ar klientu apkalpošanas centru.
Tas viss ir darīts, lai Jūs kā mūsu vietnes apmeklētājs netērētu
laiku, bet gan izdarītu izvēli dažu minūšu laikā.
The 10 Most Scariest Things About Coffee Beans
Coffee Machine coffee Beans coffee machine
Your method of explaining the whole thing in this piece of writing is truly nice, every one
can without difficulty be aware of it, Thanks a lot https://lapimbeche.com/
Do you have any video of that? I’d want to find out more details.
Also visit my webpage: Physiotherapie Hardbrücke
Your method of explaining all in this article is really nice, every one be capable of simply understand it, Thanks a
lot https://lepetitdep.ca/en/products/domaine-des-15-lots-sirop-d-erable-fonce
buy lisinopril mexico: cheapest price for lisinopril india – lisinopril 40 mg price