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://www.ginekolog-rukoeb1.ru .
В поисках способа найти и купить разные товары без лишних хлопот? Тогда наш веб-сайт – Kraken https://xn--krakn-m0a.cc , станет для вас отличным выбором. У нас вы можете приобретать и продавать что угодно, не боясь за свою анонимность. Мы предлагаем оптимальные условия на просторах мирового даркнета и работаем во всех странах мира. На нашем маркетплейсе вы найдете все необходимые продукты.
The rise of online casinos has revolutionized the gambling industry, bringing players the excitement of real casinos straight to their screens. Now, gamblers don’t have to travel to experience the thrill of betting, as the full casino experience is accessible from desktops, tablets, and smartphones.
The Appeal of Online Gambling
The surge in popularity of online casinos is driven by several factors. One of the biggest advantages is accessibility. While land-based casinos have restrictions, virtual casinos allow you to play whenever it suits you best.
Another major reason for their popularity is the sheer variety of games. Physical casinos may offer a few hundred games at best, but digital platforms feature thousands. From classic fruit machines to cutting-edge video slots with immersive themes, the choices are practically limitless.
Stay updated with the latest casino news, exclusive bonuses, and expert tips—follow us online aviator game
How Online Casinos Keep Players Engaged
The abundance of promotions is one of the key benefits of playing at online casinos. Many platforms offer newcomers fantastic welcome packages, boosting their bankroll instantly. Loyal customers are rewarded with tiered programs, reloading bonuses, and special incentives.
Luck vs. Skill in Online Gambling
While many casino games are based purely on luck, some require skill and strategy. Poker, for instance, is a game of skill where experienced players can outplay beginners by reading opponents and making calculated decisions. If you prefer a fast-paced, unpredictable experience, slots and roulette provide thrilling, luck-based gameplay.
How to Gamble Responsibly Online
As exciting as online gambling can be, it’s essential to practice responsible gaming. By setting strict financial limits and staying disciplined, players can prevent gambling from becoming a problem. Licensed casinos provide responsible gambling measures, such as cooling-off periods and withdrawal restrictions, to help players stay in control.
Share Your Casino Experience
Are you an online casino enthusiast? What’s your go-to game? Share your thoughts and experiences in the comments below!
dark market list https://github.com/darkmarketlinkp22jr/darkmarketlink – dark web market
Your style is unique compared to other people I have read stuff from.
Thank you for posting when you’ve got the opportunity, Guess I’ll just bookmark this site.
Wonderful beat ! I would like to apprentice at the same time
as you amend your site, how could i subscribe for a blog web site?
The account helped me a acceptable deal. I have been a little bit acquainted of this your broadcast provided bright
clear idea
мостбет регистрация мостбет регистрация .
easy canadian pharm: reputable canadian online pharmacies – canada drugs reviews
dark markets 2022 https://github.com/darknetdruglinksvojns/darknetdruglinks – tor market
online pharmacy discount code http://familypharmacy.company/# Best online pharmacy
free dark web https://github.com/darknetmarkets2025/darknetmarketlinks – dark web sites darknet drug market
1win.online скачать https://bbcc.com.kg/ .
888starz Cameroun
Всем привет! Может кто знает, где почитатьполезные статьи о займах? Пока нашел – ac-fors.ru
1вин официальный сайт 1вин официальный сайт .
online pharmacy no prescription https://discountdrugmart.pro/# discount drug pharmacy
I think the admin of this website is in fact working hard in support of his website,
for the reason that here every material is quality based stuff.
The digital era has reshaped how people experience gambling, making online casinos more popular than ever, making it more accessible, convenient, and thrilling than ever before. No longer do players need to visit physical casinos, to enjoy their favorite games—now, all the action is available at the click of a button.
The Appeal of Online Gambling
More and more players are choosing online gambling for its unmatched convenience and variety. A key benefit is that online casinos are available anytime, anywhere. While land-based casinos have restrictions, virtual casinos allow you to play whenever it suits you best.
Another major reason for their popularity is the sheer variety of games. Physical casinos may offer a few hundred games at best, but digital platforms feature thousands. Whether you love old-school slots or cinematic video games, there’s something for everyone.
Stay updated with the latest casino news, exclusive bonuses, and expert tips—follow us aviator official website
Bonuses, Rewards, and Promotions
Bonuses and special offers make online gambling even more enticing. Many platforms offer newcomers fantastic welcome packages, boosting their bankroll instantly. Regular players can take advantage of loyalty programs, cashback deals, and exclusive VIP rewards.
Games of Chance vs. Games of Strategy
Depending on your preferences, you can choose between pure chance games or those where skill makes a difference. Poker, for instance, is a game of skill where experienced players can outplay beginners by reading opponents and making calculated decisions. If you prefer a fast-paced, unpredictable experience, slots and roulette provide thrilling, luck-based gameplay.
Responsible Gambling & Choosing a Safe Casino
As exciting as online gambling can be, it’s essential to practice responsible gaming. By setting strict financial limits and staying disciplined, players can prevent gambling from becoming a problem. Reputable platforms also promote responsible gaming by offering tools like deposit limits, self-exclusion, and links to gambling support organizations.
Share Your Casino Experience
Are you an online casino enthusiast? What’s your go-to game? Tell us about your biggest wins or best casino moments!
Алкогольное отравление может привести к серьезным последствиям, если не принять меры вовремя. Симптомы, при которых капельница становится необходимой, могут включать интенсивные головные боли, тошноту, головокружение и рвоту. Также она показана, если запой длится больше 48 часов без заметных улучшений. Важно, что лечение может быть организовано без визита в клинику, что особенно удобно для тех, кто не может или не хочет покидать дом.
Получить больше информации – http://kapelnica-ot-zapoya-ekb55.ru
ставки на спорт бишкек fabc.com.kg .
darkmarket link https://github.com/darknetmarketslinks/darknetmarketlinks – dark web markets dark market link
Wow, this piece of writing is nice, my sister is analyzing these things, therefore I am going
to convey her.
darknet market links https://github.com/darknetdruglinksvojns/darknetdruglinks – darknet marketplace
dark markets 2025 https://github.com/darkwebwebsites/darkwebwebsites – darkmarket 2025 darknet drugs
8 Tips To Up Your Milton Keynes Gas Engineers Game Gas Engineers Milton Keynes
My partner and I stumbled over here different web page and thought I might
as well check things out. I like what I see so now i’m following you.
Look forward to looking into your web page for a second time.
dark web drug marketplace https://github.com/darknetmarkets2025/darknetmarketlinks – darknet sites dark web links
Hello, just wanted to tell you, I enjoyed this post.
It was funny. Keep on posting!
Woah! I’m really digging the template/theme of
this blog. It’s simple, yet effective. A lot of times it’s hard to get that “perfect balance” between user friendliness
and visual appeal. I must say you’ve done a amazing job with
this. Also, the blog loads super quick for me on Chrome.
Superb Blog!
Mega India Pharm: Mega India Pharm – MegaIndiaPharm