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
darknet market lists dark web market links darknet links
I truly love your website.. Great colors & theme.
Did you build this amazing site yourself? Please reply back as
I’m wanting to create my own personal website
and want to know where you got this from or exactly what the
theme is called. Thank you!
Pemain harus menetapkan batas saat bermain https://slotdemo.auction/# Slot dengan fitur interaktif semakin banyak tersedia
888starz casino https://www.fbioyf.unr.edu.ar/evirtual/mod/forum/discuss.php?d=47707
bitcoin dark web onion dark website
Вывод из запоя представляет собой важный этап в процессе лечения алкогольной зависимости. Это медицинская процедура, необходимая для устранения токсических веществ, накопленных в организме в результате длительного употребления алкоголя. Алкогольная зависимость может вызывать множество проблем, включая физические и психоэмоциональные расстройства. Своевременное вмешательство специалистов помогает минимизировать риски и способствует восстановлению здоровья пациента.
Изучить вопрос глубже – narkologiya vyvod iz zapoya na domu
Meds information sheet. Brand names.
doxycycline immunosuppressant
Actual news about pills. Get information now.
Hi, Neat post. There’s a problem with your website in internet
explorer, would test this? IE nonetheless is the market leader and a large portion of other people
will miss your fantastic writing because of this problem.
https://slotdemo.auction/# Pemain bisa menikmati slot dari kenyamanan rumah
How Online Casinos Are Becoming a Worldwide Trend
Internet-based gambling hubs have transformed the gaming scene, providing an exceptional degree of convenience and range that conventional venues can’t match. Over time, a large audience globally have chosen the thrill of digital casino play due to its ease of access, engaging traits, and widening range of offerings.
One of the main appeals of digital gambling sites is the incredible array of games at your disposal. Whether you like rolling classic slots, exploring story-driven video-based games, or strategizing in traditional table offerings like Roulette, virtual venues feature infinite possibilities. Numerous services even include interactive dealer games, allowing you to connect with actual dealers and co-players, all while enjoying the authentic vibes of a brick-and-mortar establishment from anywhere you want.
If you’re new with the world of virtual gambling or would like to explore reliable sites, why not engage with our growing social network? It’s a platform where players post stories, making it easier for you to maximize your virtual play. Join the conversation and visit us now: bet sport 22
In addition to diversity, online casinos shine availability.
Slot dengan fitur interaktif semakin banyak tersedia http://slotdemo.auction/# Kasino sering mengadakan turnamen slot menarik
garuda888 slot garuda888 slot Slot klasik tetap menjadi favorit banyak orang
demo slot pg demo slot pg Pemain sering mencoba berbagai jenis slot
darknet drugs dark web link
http://slotdemo.auction/# Pemain bisa menikmati slot dari kenyamanan rumah
darknet drug links tor drug market
На сайте букмекерской конторы Мостбет вы можете официально зайти и делать ставки на спортивные события онлайн безопасно и легально.
http://garuda888.top/# Banyak pemain mencari mesin dengan RTP tinggi
dark web link dark web drug marketplace
My partner and I absolutely love your blog and find almost all of your post’s
to be just what I’m looking for. can you offer guest writers to write content in your case?
I wouldn’t mind composing a post or elaborating on most of
the subjects you write in relation to here. Again, awesome web log!
Good post. I learn something totally new and challenging on blogs I stumbleupon everyday.
It will always be interesting to read through articles from other writers and use something from other websites.
slot demo pg gratis slot demo rupiah Kasino memastikan keamanan para pemain dengan baik
https://preman69.tech/# Banyak pemain berusaha untuk mendapatkan jackpot
http://slotdemo.auction/# Permainan slot bisa dimainkan dengan berbagai taruhan
Permainan slot bisa dimainkan dengan berbagai taruhan https://garuda888.top/# Permainan slot mudah dipahami dan menyenangkan
I believe everything said made a great deal of sense.
However, what about this? suppose you typed a catchier title?
I mean, I don’t want to tell you how to run your blog, however suppose you added a post title to
possibly get folk’s attention? I mean JS 依照元素出現數量排序 –
馬老師 雲端研究室 is kinda plain. You
should peek at Yahoo’s home page and note how they create news headlines to grab viewers to open the
links. You might add a video or a related picture
or two to get people interested about everything’ve written. In my opinion, it might make your website a little livelier.
Mesin slot sering diperbarui dengan game baru https://slot88.company/# Slot menawarkan kesenangan yang mudah diakses
Your style is so unique compared to other people I’ve read stuff from.
Thanks for posting when you’ve got the opportunity, Guess I’ll
just book mark this page.
dark web marketplaces dark market list
Slot dengan pembayaran tinggi selalu diminati https://slot88.company/# Banyak kasino memiliki program loyalitas untuk pemain