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
Online medicine home delivery: Order medicine from India to USA – top 10 online pharmacy in india
drugs online: cheap drugs online – medication drugs
Patio Heater Gas Cylinder: The Ugly Real Truth Of Patio Heater
Gas Cylinder patio Gas
buy medicines online in india: Indian pharmacy international shipping – mail order pharmacy india
best online drugstore cheaper medications prescription meds without the prescriptions
https://pharm24.pro/# canadian online pharmacy
canadian pharmacy
купить диплом в тагиле prema-diploms.ru .
Manufacturers offer low price of target pharmacy propecia when they are buying it online.
20 Truths About Mystery Boxes: Busted Mystery box sites (http://www.tianxiaputao.com/bbs/home.php?mod=space&uid=767781)
Диплом вуза купить официально с упрощенным обучением в Москве
I think what you posted made a great deal of sense. But, what about this?
suppose you added a little content? I ain’t suggesting your content is not solid, but suppose you
added something that makes people want more? I mean JS 依照元素出現數量排序 – 馬老師 雲端研究室 is a
little boring. You should look at Yahoo’s
front page and watch how they create news headlines to get people interested.
You might add a video or a related pic or two to get readers interested about
everything’ve got to say. Just my opinion, it would make your website
a little bit more interesting.
Spot on with this write-up, I honestly believe this web site needs
a lot more attention. I’ll probably be back again to read more, thanks for the info!
12 Stats About Audi Spare Key To Make You Look Smart Around Other People cheap
Аттестат 11 класса купить официально с упрощенным обучением в Москве
I simply couldn’t depart your site before suggesting that I really loved the standard info a person provide on your
guests? Is going to be back regularly to check up on new posts
purple pharmacy mexico price list mexico pharmacy cheap mexican online pharmacies prescription drugs
Thanks for finally writing about > JS 依照元素出現數量排序 – 馬老師 雲端研究室 < Liked it!
At this time I am going to do my breakfast, once having my breakfast coming yet again to read more news.
https://w1.resultnomor.us/
Its like you read my mind! You appear to know so
much about this, like you wrote the book in it or something.
I think that you can do with some pics to drive the message home a little bit, but other than that, this is excellent blog.
A great read. I’ll definitely be back.
Официальная покупка школьного аттестата с упрощенным обучением в Москве
We are a group of volunteers and starting a new scheme in our community.
Your website offered us with valuable info to work on. You have done a formidable job and our entire community will be thankful
to you.
Medication prescribing information. Cautions.
can i order cheap benicar
All news about medicines. Get now.
indian pharmacies safe: indian pharm 24 – indian pharmacy
pharmacy website india Indian pharmacy to USA online shopping pharmacy india
It’s really a nice and helpful piece of information. I’m happy that you
just shared this helpful info with us. Please stay us up to
date like this. Thank you for sharing.
world pharmacy india Indian pharmacy to USA reputable indian online pharmacy
mexican pharmaceuticals online mexican drugs purple pharmacy mexico price list
When someone writes an paragraph he/she keeps the image of a
user in his/her mind that how a user can understand
it. Thus that’s why this paragraph is great. Thanks!
Also visit my blog post :: dubstep
20 Trailblazers Leading The Way In Wall Fireplace Electric Electric Firesuite
Citroen Berlingo Van Key Replacement Isn’t As Tough As You Think
replacement citroen c1 key nottingham – http://www.stes.Tyc.edu.tw/xoops/modules/profile/userinfo.php?uid=1802269 –