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
%%
Here is my web page :: Cbd oil sweets uk
%%
Here is my site … leather trench Coat mens (yourspaceaway.com)
%%
Feel free to surf to my homepage … sexdoll for men (http://bulangiul.net/sexdollss611711)
berlin telegram group drugs deep sea darknet market
What i don’t understood is in truth how you’re now not actually
a lot more smartly-appreciated than you may
be now. You are so intelligent. You already know therefore significantly in terms of this subject, produced me personally
imagine it from a lot of numerous angles. Its like women and men aren’t fascinated except it’s one thing to do with Girl gaga!
Your own stuffs great. At all times handle it up!
Guess the exchange rate, bitcoin and get money. Start with
$10 and you can earn up to $1000 in a day, see how Here
%%
Here is my web blog … Double Glazing In Enfield (Penpek.Com)
Hola! I’ve been reading your blog for a while now
and finally got the bravery to go ahead and give you a shout
out from Austin Texas! Just wanted to say keep up
the fantastic work!
darknet dream market reddit Abacus Market darknet
I’m extremely impressed with your writing skills and also with
the layout on your weblog. Is this a paid theme or did you modify it
yourself? Anyway keep up the nice quality writing, it’s rare
to see a great blog like this one Fit Today Wellness Keto.
Abacus Market darknet deep web links updated
%%
Visit my webpage … Sexdolls Sale
I read this article fully on the topic of the comparison of most recent and preceding technologies,
it’s amazing article.
мега официальный сайт магазины даркнета
What’s up it’s me, I am also visiting this web site regularly,
this site is really pleasant and the visitors are in fact
sharing fastidious thoughts.
%%
My site :: investors Looking for projects To fund in South africa
сайты даркнет даркнет ссылки
THC gummies paris
gummies are just one of the most preferred THC products.
darknet market reddit darknet adress
canadianpharmacyworld canadian online drugstore
%%
Check out my site Gambling – Holycrosslutheran-Emma-Mo.Com,
ссылки на даркнет mega онион сайт
dark web onion markets darknet bank accounts
bohemia market link exploit market darknet
%%
Here is my page :: cbd pills For pain
%%
My homepage; best Spf moisturiser
This is very interesting, You’re a very skilled blogger. I have joined
your rss feed and look forward to seeking more of your magnificent post.
Also, I’ve shared your web site in my social networks!
https://foxcracks.com/
74cd785c74 orunbeth
%%
Here is my website Sexdoll Sales
darknet bitcoin market how to access darknet markets reddit