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://clomidonpharm.com/# can i buy generic clomid without rx
Интересные статьи о займах – https://www.bnkomi.ru/data/relize/140874/
https://cipharmdelivery.com/# cipro online no prescription in the usa
I am not sure where you’re getting your info, but good
topic. I needs to spend some time learning more or understanding more.
Thanks for great info I was looking for this info for my mission.
Всё, что нужно знать о покупке аттестата о среднем образовании
Quality content is the main to invite the users to go
to see the site, that’s what this web page is providing.
Excellent weblog here! Additionally your web site loads up very fast!
What host are you the usage of? Can I get your affiliate hyperlink
to your host? I wish my website loaded up as fast as yours lol
Here is my web page: alpha bites buy
Pills information. Generic Name.
where can i get cheap compazine price
Actual information about medicines. Get information now.
What’s The Current Job Market For Inbuilt Fridge Freezer
Professionals Like? inbuilt fridge freezer (Caleb)
dark web search engine dark market onion dark web link
https://pechi-troyka.ru/content/pages/megapari_promokod.html
Полезные советы по покупке диплома о высшем образовании без риска
“Anyone else find it challenging to choose between styles? A good ###nyKeyword### could help clarify things!” Minimalist fencing contractors
Just saw a before-and-after of a pressure cleaned home, and wow, the distinction is unbelievable! More about this at pressure washing conway
http://otolar-centre.ru/includes/pgs/1xbet_promokod_registraciya.html
How New Crypto Casino Altered My Life For The Better Best Crypto Casino Games
Today, I went to the beach front with my children.
I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the
shell to her ear and screamed. There was a hermit crab inside and it pinched her ear.
She never wants to go back! LoL I know this is completely
off topic but I had to tell someone! https://Utahsyardsale.com/author/celestev758/
http://amoxstar.com/# buy amoxicillin from canada
You have made some really good points there.
I checked on the internet for more info about the issue and
found most individuals will go along with your views on this web site. https://Hariharparagovernmentiti.com/2024/12/08/clinique-esthetique-en-france-votre-destination-pour-des-traitements-esthetiques-de-qualite-2/
Amazingservice Keechi Creek Builders new home builders in houston tx
The Biggest Issue With Key Fob Volvo And How You Can Resolve It
Volvo new key
Как купить аттестат 11 класса с официальным упрощенным обучением в Москве
You can even make little changes to the door framework without a license.
With so many builders out there home builders in houston area
After seeing all these before-and-after photos online how to clean a roof
Вопросы и ответы: можно ли быстро купить диплом старого образца?
Whats up this is kinda of off topic but I was wondering if blogs use WYSIWYG
editors or if you have to manually code with HTML.
I’m starting a blog soon but have no coding expertise
so I wanted to get guidance from someone with experience.
Any help would be greatly appreciated!
See What Long-Range Mobility Scooters Tricks The Celebs Are Utilizing long-range Mobility scooters
Thanks for the comprehensive read. Find more at cost of pressure washing
With thanks, I value it.
My page – https://Hariharparagovernmentiti.com/2024/12/22/testing-the-house-with-cable-test-equipment/