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
https://fastpillseasy.com/# best online ed treatment
http://maxpillsformen.com/# Generic Cialis price
See What Fridges & Freezers Tricks The Celebs Are Utilizing fridges & Freezers
카지노사이트 카지노사이트
카지노사이트 카지노사이트 카지노사이트 카지노사이트 카지노사이트
Having read this I believed it was really informative.
I appreciate you taking the time and energy to put this informative article together.
I once again find myself spending a lot of time both reading and leaving comments.
But so what, it was still worth it!
Just got a magnificent haircut that I definitely like! If you intend to discover an experienced stylist, do not neglect to look into treatment keratin smooth for ideas
Thanks for the clear breakdown. More info at pressure washing Near Me
дипломы купить челны дипломы купить челны .
http://fastpillsformen.com/# Viagra without a doctor prescription Canada
Good day! I know this is kind of off topic
but I was wondering which blog platform are you using for this site?
I’m getting tired of WordPress because I’ve had issues with hackers
and I’m looking at options for another platform.
I would be great if you could point me in the direction of a good platform.
Tadalafil price buy cialis online Cialis over the counter
If some one wants expert view on the topic of blogging and site-building after that
i propose him/her to pay a visit this weblog, Keep up the nice work.
загранпаспорт оформить загранпаспорт оформить .
I do not even know how I ended up here, but I thought this post was great.
I do not know who you are but definitely you are going to a famous blogger if you aren’t
already 😉 Cheers!
카지노사이트 카지노사이트 카지노사이트 카지노사이트 카지노사이트 카지노사이트 카지노사이트
купить диплом в северодвинске prema-diploms.ru .
Do you recognize the value of normal trims? It really makes a distinction in preserving healthy and balanced hair! Look into ulta beauty salon for even more hair treatment ideas
Excellent post. I was checking constantly this blog and I am impressed!
Extremely useful information specifically the last part :
) I care for such information much. I was looking for this certain info for a long time.
Thank you and good luck.
If you are traveling Austin, don’t omit out on renting a boat! I found substantive suggestions at Banana Boat Rentals Boat Rental
The 1win promo code: MAX500WIN. This 1Win bonus code 2025 rewards new players with a 500% bonus up to $1025. Valid codes for receiving bonuses without a deposit for new and old users. Hurry to get them today! Activate the promo code 1win and get a generous welcome bonus of up to 500% on your first four deposits.
https://japasquare.app/blogs/2277/Unlock-Exciting-Opportunities-with-the-1Win-Free-Bonus-Code-2025 – 1win promo code
I didn’t realize how much clutter I had up until I started my scrap removal job. It was frustrating at first, now I feel so relieved 1800 got junk cost
How Techniques With A Network Marketing Program 에볼루션 가품
купить диплом о профпереподготовке prema-diploms.ru .
Покупка диплома о среднем полном образовании: как избежать мошенничества?
купить диплом с отличием купить диплом с отличием .
Szybka sprzedaż nieruchomości to świetne rozwiązanie dla osób, które potrzebują natychmiastowej gotówki. Dzięki temu procesowi można uniknąć długotrwałych negocjacji i formalności szybka sprzedaż nieruchomości
my website :: Highstakesweeps Online
It’s amazing how chiropractic care can improve overall wellness Chiropractic adjustment for auto injuries
где можно купить диплом где можно купить диплом .
Great goods from you, man. I have understand your stuff previous to and you’re just
extremely fantastic. I really like what you have acquired here, certainly like what you’re saying and the
way in which you say it. You make it enjoyable and you still take care of to keep it wise.
I cant wait to read far more from you. This is actually a wonderful site.