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
Узнай все о двустороннее варикоцеле варикоцеле причины
Medicine information for patients. What side effects?
where can i get bactrim without insurance
Actual trends of drugs. Read information now.
cheap priligy: max pharm – dapoxetine online
нарколог на дом http://zavitai.mybb.social/viewtopic.php?id=89 .
This is the perfect webpage for anybody who would like to understand this topic.
You realize a whole lot its almost hard to argue with
you (not that I really would want to…HaHa). You certainly put
a fresh spin on a topic that has been discussed for decades.
Wonderful stuff, just excellent!
amoxicillin 500 mg brand name: com pharm – buy cheap amoxicillin
Very descriptive article, I liked that bit.
Will there be a part 2?
Официальная покупка диплома вуза с упрощенной программой обучения
Ԝе are a grou оf volunteers and ߋpening a brand neew
scheme іn our community. Υour website provided uѕ with valuable information too work on.
Y᧐u haѵe done an impressive process and ourr еntire community
ѡill be thankful tо you.
Нere is my bllg … KasToto
I’ve been surfing on-line more than 3 hours these days,
but I by no means found any fascinating article like yours.
It is pretty value sufficient for me. In my opinion, if all web owners and
bloggers made just right content material as you did, the internet will probably be
a lot more helpful than ever before.
how to buy generic clomid online: rex pharm – get clomid no prescription
It’s a pity you don’t have a donate button! I’d most certainly donate to this fantastic blog!
I suppose for now i’ll settle for bookmarking and adding your
RSS feed to my Google account. I look forward to
new updates and will talk about this site with my Facebook group.
Talk soon!
can you buy prednisone over the counter in canada: cheap prednisone – prednisone uk buy
Всё о покупке аттестата о среднем образовании: полезные советы
clomid for sale: cheap clomid – where can i get clomid without prescription
30mg prednisone: cheap generic prednisone – 80 mg prednisone daily
how to buy generic clomid: rexpharm – generic clomid
amoxil generic: amoxil – canadian pharmacy amoxicillin
Currently it seems like Movable Type is the preferred blogging platform out
there right now. (from what I’ve read) Is that what you’re using on your blog?
darkmarket list darknet drug store dark web markets
Или никакого обучения? Абсолютно.
Look into my web page – https://robotech.com/forums/viewthread/2227291
Пошаговая инструкция по официальной покупке диплома о высшем образовании
Как правильно купить диплом колледжа и пту в России, подводные камни
10 Strategies To Build Your Accident Attorney
Empire accident and injury
Thanks for sharing such a nice thought, piece of writing
is good, thats why i have read it fully
Pills information sheet. What side effects?
spironolactone rebound edema
All information about drug. Get information here.
I have read several just right stuff here. Certainly price bookmarking for revisiting.
I surprise how much attempt you put to make such a excellent informative website.
http://www.pgyer.com/apk/apk/com.daddy.c115546 Daddy casino скачать Андроид
amoxicillin 500 mg tablet price: amoxil – generic amoxicillin cost
вывод из запоя на дому ростов-на-дону http://zarabotokdoma.creartuforo.com/viewtopic.php?id=11471/ .