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
#file_links[“C:\xrukeys\kw-darknet.txt,1,S – #file_links[“C:\xrukeys\kw-darknet.txt,1,S –
dark web links dark web market links
best darknet markets darknet market lists
The Internet has created a wealth of new opportunities for those who enjoy playing poker.
Online poker has seen a rapid increase in popularity in the last
few years.
Also visit my blog: casino (Kenton)
#file_links[“C:\xrukeys\kw-darknet.txt,1,S – #file_links[“C:\xrukeys\kw-darknet.txt,1,S –
#file_links[“C:\xrukeys\kw-darknet.txt,1,S – #file_links[“C:\xrukeys\kw-darknet.txt,1,S –
deep web markets dark web sites links
darknet market list onion market
best darknet markets best darknet markets
drug markets onion tor marketplace
whoah this weblog is fantastic i like reading your posts.
Stay up the great work! You understand, lots of individuals are looking around for this information, you can help them greatly.
dark websites drug markets onion
Online gambling is governed numerous rules and regulations.
In the US, for example it is not possible to establish an online gambling site in the country where you live however, you can base it elsewhere.
Also visit my homepage – experience
darknet drug links tor markets 2022
dark market 2022 drug markets onion
#file_links[“C:\xrukeys\kw-darknet.txt,1,S – #file_links[“C:\xrukeys\kw-darknet.txt,1,S –
dark market link dark web link
dark market dark web drug marketplace
tor market links darkmarket url
drug markets dark web deep web drug links
Heya i’m for the first time here. I found this
board and I find It really useful & it helped me out much.
I hope to give something back and aid others like
you aided me.
Fabulous, what a web site it is! This web site provides valuable facts to us, keep it up.
Here is my blog: Mesothelioma law
Keep up the fantastic work, I read few content
on this internet site and I conceive that your website is really interesting and contains lots of excellent info.
bitcoin dark web dark websites
tor darknet darknet sites
deep web drug markets tor marketplace
deep web drug url tor darknet
tor markets darkmarket list
darkmarkets deep web drug markets
tor markets darkmarket link