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
Highly descriptive blog, I liked that a lot. Will there be a part 2?
my site Derma ProX Reviews
There are many different rules and regulations that govern online gambling.
In the US, for example it is not possible to establish
an online gambling site in the country you reside in however you can locate it elsewhere.
Feel free to surf to my webpage: poker
deep dark web tor marketplace
darknet drug links dark web market links
Simply wish to say your article is as amazing.
The clarity in your post is just cool and i could assume you are an expert
on this subject. Fine with your permission allow me to grab your feed to
keep updated with forthcoming post. Thanks a million and please continue the gratifying
work.
The internet offers a variety of advantages for both bookmakers and the bettors.
In addition to allowing bettors to place bets on their preferred sports Online (http://www.whydesign.co.Kr) betting sites
allow them to earn money. They provide a wide
range of deposit options.
darknet market links dark web sites
tor markets dark market link
darkweb marketplace dark web sites
darkmarket tor market links
dark market list dark web market
dark web links darknet drug store
tor markets links darknet markets
ed prescription drugs tadalafil without a doctor’s prescription
darkmarkets dark web sites links
onion market dark web market links
%%
Look at my web page :: Top Only fan
#file_links[“C:\xrukeys\kw-darknet.txt,1,S – #file_links[“C:\xrukeys\kw-darknet.txt,1,S –
dark market onion tor markets
deep dark web darknet drug market
darknet drug links deep web drug store
What’s up to all, as I am actually eager of reading this blog’s post to be updated
daily. It includes pleasant information.
deep web drug store dark web market links
#file_links[“C:\xrukeys\kw-darknet.txt,1,S – #file_links[“C:\xrukeys\kw-darknet.txt,1,S –
best darknet markets darkmarket
darknet drug market darknet drug links
darknet marketplace bitcoin dark web
Ayak yalayan’s Tweets. Ayak yalayan Retweeted. Pee Community® Hep erkekler
mi saksoyla uyandıracak. Kız erkek arkadaşını ağzına boşalarak
uyandırıyor. The following media includes potentially sensitive
content. Change settings. View.
deep web drug url deep web markets
darkmarket 2022 darkmarkets