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
It’s inspiring to see numerous individuals interested in learning CPR lately! Let’s keep spreading awareness– take a look at First Aid course Near Me
easy canadian pharm reputable canadian pharmacy canada pharmacy online
1win.pro http://bbcc.com.kg .
мосьет мосьет .
deep dark web https://github.com/tormarkets2025ukaz1/tormarkets2025 – darknet market lists
мостбет вход официальный сайт http://www.gtrtt.com.kg .
Hi! I’m at work browsing your blog from my new iphone
3gs! Just wanted to say I love reading your blog and look
forward to all your posts! Carry on the outstanding work!
вход мостбет http://www.gtrtt.com.kg .
tor market links https://github.com/tormarkets2025ukaz1/tormarkets2025 – tor markets 2022
мостбет официальный сайт скачать http://www.gtrtt.com.kg .
xxl mexican pharm: mexico drug stores pharmacies – xxl mexican pharm
darknet drugs https://github.com/darknetmarkets2025/darknetmarketlinks – deep web drug markets free dark web
dark web market links https://github.com/darknetmarketslinks/darknetmarketlinks – free dark web dark web sites
mostbet giri? http://gtrtt.com.kg/ .
1 win официальный [url=http://www.bbcc.com.kg]http://www.bbcc.com.kg[/url] .
1вин войти http://fabc.com.kg/ .
Cheapest online pharmacy: online pharmacy delivery usa – family pharmacy
darknet websites https://github.com/darknetmarketlinks2025/darknetmarkets – dark market url
1вин регистрация http://www.fabc.com.kg .
dark web market https://github.com/tormarkets2025ukaz1/tormarkets2025 – darknet market links
Всем привет! Подскажите, где найтиразные блоги о займах? Пока нашел – 777uspeh.ru
1win официальный 1win официальный .
I am not sure where you are getting your information,
but great topic. I needs to spend some time learning more or understanding more.
Thanks for great info I was looking for this information for my mission.
cheapest pharmacy to get prescriptions filled: Cheapest online pharmacy – Online pharmacy USA
dark websites https://github.com/darknetdruglinksvojns/darknetdruglinks – onion market
pharmacy discount coupons https://discountdrugmart.pro/# discount drug pharmacy
What’s up to all, the contents present at this website are genuinely remarkable for people knowledge, well, keep up
the nice work fellows.
my web site :: เมือง คาสิโน
How Online Casinos Are Becoming a Worldwide Trend
Digital casinos have modernized the gambling industry, delivering a unique kind of comfort and breadth that physical venues don’t provide. Over the past decade, countless gamblers internationally have welcomed the excitement of virtual casinos in light of its always-open nature, exciting features, and ever-expanding range of offerings.
One of the most compelling reasons of online gaming options is the unparalleled array of titles on offer. Whether you love rolling traditional reel games, diving into story-driven visual slot games, or testing your strategy in card and board games like Roulette, internet-based gambling sites offer infinite options. Numerous services moreover introduce interactive dealer games, enabling you to participate with actual dealers and opponents, all while enjoying the immersive environment of a physical gaming house in your own space.
If you’re new with the world of virtual casino play or seek to delve deeper into proven options, why not participate in our vibrant interactive platform? It’s a place where gaming aficionados offer tips, guiding you to enjoy more of your casino activities. Explore the discussions and start your journey now: bet on red
Beyond variety, internet-based gambling hubs stand out constant connectivity.
Base Bridge: Your Gateway to Seamless Asset Transfer
As the digital landscape expands, transferring assets across different blockchain networks has become increasingly important. Base Bridge offers a robust solution for managing digital assets efficiently and securely.
base bridge crypto
What is Base Bridge?
Base Bridge is a cutting-edge platform designed to facilitate the seamless transfer of assets between different blockchain networks. By providing a bridge across these networks, users can enjoy enhanced connectivity and flexibility.
Key Features of Base Bridge
Interoperability: Connects multiple blockchain networks for seamless asset transfers.
Security: Ensures secure transactions with state-of-the-art encryption.
Speed: Fast transactions ensure access to funds without delays.
Benefits of Using Base Bridge
Whether you’re a developer, investor, or enthusiast, Base Bridge offers numerous benefits including:
Reduced Costs: Minimize fees associated with cross-chain transactions.
Broader Access: Gain access to a wider array of assets and networks.
User-Friendly Experience: Intuitive interface that caters to both novice and advanced users.
How to Get Started with Base Bridge
Embarking on your Base Bridge journey is straightforward:
Sign up on the .
Connect your digital wallet.
Choose the networks and assets you wish to transfer.
Execute transactions quickly and securely.
Base Bridge stands as a pillar in the future of digital asset management, paving the way for a more interconnected blockchain ecosystem. By leveraging Base Bridge, users can confidently navigate the complexities of digital asset exchanges.
Visit today to explore the full potential of your digital assets.
The digital era has reshaped how people experience gambling, making online casinos more popular than ever, allowing players to enjoy high-quality gaming without leaving their homes. 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.
Reasons Why Online Casinos Are Booming
There are many reasons why online casinos have gained massive traction. A key benefit is that online casinos are available anytime, anywhere. While land-based casinos have restrictions, internet-based casinos never close, ensuring round-the-clock entertainment.
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 lucky jet download
Bonuses, Rewards, and Promotions
The abundance of promotions is one of the key benefits of playing at online casinos. New players are often welcomed with attractive sign-up bonuses, deposit matches, and free spins. Regular players can take advantage of loyalty programs, cashback deals, and exclusive VIP rewards.
Luck vs. Skill in Online Gambling
While many casino games are based purely on luck, some require skill and strategy. In games like poker, knowledge and tactics can give players a significant edge over less experienced opponents. If you prefer a fast-paced, unpredictable experience, slots and roulette provide thrilling, luck-based gameplay.
Responsible Gambling & Choosing a Safe Casino
To ensure a positive experience, it’s vital to play responsibly and within limits. Smart bankroll management and self-control help players maintain a healthy approach to gambling. Reputable platforms also promote responsible gaming by offering tools like deposit limits, self-exclusion, and links to gambling support organizations.
Join the Discussion!
Are you an online casino enthusiast? What’s your go-to game? Tell us about your biggest wins or best casino moments!