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
mexico pharmacies prescription drugs
http://cmqpharma.com/# п»їbest mexican online pharmacies
purple pharmacy mexico price list
pharmacies in mexico that ship to usa: mexico pharmacy – pharmacies in mexico that ship to usa
Asthma symptom severity prevention plans
I’d like to find out more? I’d care to find out some additional
information.
Greetings! Very helpful advice in this particular article!
It is the little changes that will make the most significant changes.
Thanks a lot for sharing!
pharmacies in mexico that ship to usa
http://cmqpharma.com/# purple pharmacy mexico price list
buying prescription drugs in mexico
mexican drugstore online: mexican pharmacy online – п»їbest mexican online pharmacies
mexican online pharmacies prescription drugs: mexican pharmacy online – mexican pharmacy
10 Locations Where You Can Find Asbestos Claims Payout https://www.9363280.xyz/
Productive High Ticket Marketing – 6 Steps To Affect Your
High Ticket Marketing 구글상위노출 업체 (filmsgood.ru)
What’s The Current Job Market For Double Glazed Window Repairs Professionals Like?
double glazed window Repairs
Hello, after reading this amazing piece of writing i am as well happy to share my experience here with mates.
my web blog :: asbestos removal ottawa Ontario
mexico drug stores pharmacies
http://cmqpharma.com/# medicine in mexico pharmacies
purple pharmacy mexico price list
how to buy cheap caduet prices
order cheap advair diskus online
buying from online mexican pharmacy
https://cmqpharma.online/# best online pharmacies in mexico
purple pharmacy mexico price list
mexican pharmacy: cmq pharma – mexican online pharmacies prescription drugs
ремонт стиральных машин адреса ремонт стиральных машин адреса .
срочный ремонт стиральных машин https://centr-remonta-stiralnyh-mashin.ru .
mexican pharmaceuticals online: mexican pharmacy – mexican border pharmacies shipping to usa
ремонт стиральных машин дома на выезде https://www.centr-remonta-stiralnyh-mashin.ru .
I know this if off topic but I’m looking into starting my
own weblog and was wondering what all is required to get set up?
I’m assuming having a blog like yours would cost
a pretty penny? I’m not very internet savvy
so I’m not 100% certain. Any tips or advice would be greatly appreciated.
Many thanks
For these kicking off a job search, Safani advises consumers to take into consideration how all aspects of a new position measure up.
Also visit my web page :: Classic
п»їbest mexican online pharmacies: mexican pharmacy online – mexican pharmacy
Seo Is The Wave Of The Future 구글상위노출 트래픽 (http://wordnomads.com/__media__/js/netsoltrademark.php?d=spectr-sb116.ru/user/cubbite41/)
8 Tips For Boosting Your Car Key Locksmith Game Elsy Crays
mexican rx online: mexican pharmacy – mexico drug stores pharmacies
починить стиральную машину в москве починить стиральную машину в москве .
п»їbest mexican online pharmacies: mexican online pharmacy – mexican border pharmacies shipping to usa
mexican mail order pharmacies
http://cmqpharma.com/# mexico drug stores pharmacies
purple pharmacy mexico price list