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
cheapest pharmacy for prescriptions http://familypharmacy.company/# Online pharmacy USA
mostbet register http://gtrtt.com.kg .
Mega India Pharm reputable indian pharmacies MegaIndiaPharm
Thanks for the auspicious writeup. It in truth used to be a amusement account it.
Look complex to far added agreeable from you! However,
how can we be in contact?
скачать mostbet скачать mostbet .
canadian pharmacy no prescription needed https://xxlmexicanpharm.com/# xxl mexican pharm
My programmer is trying to persuade me to move to
.net from PHP. I have always disliked the idea because of the expenses.
But he’s tryiong none the less. I’ve been using Movable-type on a variety
of websites for about a year and am worried about switching to another platform.
I have heard great things about blogengine.net.
Is there a way I can import all my wordpress posts into it?
Any kind of help would be greatly appreciated!
us pharmacy no prescription http://discountdrugmart.pro/# discount drug pharmacy
Приветствую. Подскажите, где почитатьразные блоги о займах? Сейчас читаю – centrzaymov19.ru
indian pharmacy paypal: MegaIndiaPharm – MegaIndiaPharm
darknet drug links https://github.com/darknetmarketslinks/darknetmarketlinks – dark web access the dark internet
dark market list https://github.com/darkmarketlinkp22jr/darkmarketlink – tor market url
Awesome site you have here but I was curious if you knew of any forums that cover the
same topics discussed here? I’d really love to be a part of online community where
I can get opinions from other knowledgeable individuals that share the same interest.
If you have any recommendations, please let me know. Thanks!
deep web drug url https://github.com/darknetwebsitesgflpx/darknetwebsites – tor darknet
мостбет сом мостбет сом .
easy canadian pharm: easy canadian pharm – easy canadian pharm
Ten Things You Learned In Kindergarden Which Will
Aid You In Obtaining Buy A1 And A2 Driving License Online
köp Sverige körkort
Hi! Iknow this iis kinda off topikc but I’d figured I’d ask.
Would you be interested in exchanging links or maybe guest authoring
a blog post or vice-versa? My website gods over a lot of
the same subjects as yours and I believe wee could greatly benefit from each other.
If you happen to be interested feel free to send
me an email. I loo forward to hearing from you! Awesome
blog by the way!
Look at my webpage … izmir nişan mekanı
Window Seal Repair: What’s No One Is Talking About window sealed unit replacement
free dark web https://github.com/darknetmarketslinks/darknetmarketlinks – dark markets 2025 darknet drug links
dark web links https://github.com/darknetmarketslinks/darknetmarketlinks – black internet deep web drug markets
The Reasons Buy A Category A Driving License Is More Difficult Than You Think Kup Prawo jazdy W Polsce
online pharmacy prescription https://easycanadianpharm.com/# canadian pharmacy prices
canadian pharmacy coupon http://xxlmexicanpharm.com/# mexican drugstore online
I am really impressed with your writing talents as well as
with the layout to your blog. Is this a paid subject matter or did you customize it your self?
Either way keep up the nice high quality writing, it is uncommon to see a great
weblog like this one these days..
darkweb marketplace https://github.com/darkmarketlinkp22jr/darkmarketlink – dark market list
tor markets 2025 https://github.com/darkwebmarketslinks/darkwebmarkets – dark market url dark web drug marketplace
I have read so many articles regarding the blogger lovers but this post is genuinely a good post, keep it up.
no prescription needed pharmacy http://megaindiapharm.com/# MegaIndiaPharm
tor marketplace https://github.com/darkmarketlinkp22jr/darkmarketlink – darknet market links