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
mostbet скачать mostbet скачать .
darknet market list https://github.com/darknetmarkets2025/darknetmarketlinks – dark web markets darknet seiten
9 Lessons Your Parents Taught You About High-Quality
Factory-Made Pallets High-Quality Factory-Made Pallets – telegra.Ph –
Всем привет! Может кто знает, где почитатьполезные статьи о займах? Пока нашел – antey-anapa.ru
canadian pharmacy no prescription needed https://xxlmexicanpharm.com/# xxl mexican pharm
drug markets dark web https://github.com/darknetwebsitesgflpx/darknetwebsites – dark websites
mail order pharmacy no prescription https://easycanadianpharm.com/# easy canadian pharm
legit non prescription pharmacies https://familypharmacy.company/# Online pharmacy USA
мостбет официальный http://www.gtrtt.com.kg .
MinSwap:
The Top Crypto Platform in 2025
10 Driver’s License Renew-Related Meetups
You Should Attend väGverket körkort förnya – Posteezy.Com,
discount drug pharmacy: drug mart – drug mart
dark market link https://github.com/darkwebwebsites/darkwebwebsites – darknet websites darkmarket link
mexico drug stores pharmacies: mexican rx online – buying prescription drugs in mexico
discount drugs: discount drug mart pharmacy – discount drug mart
I’m really loving the theme/design of your web site.
Do you ever run into any browser compatibility problems?
A handful of my blog readers have complained about my site not operating correctly
in Explorer but looks great in Firefox. Do you have any solutions to help fix this issue?
Are you a sports enthusiast looking to elevate your betting experience? Look no further than BetWinner, a platform that offers a seamless and thrilling way to engage with your favorite sports tournaments https://internetforum.io/betwinner-promo-code-2025-unlock-exclusive-promotions-with-lucky2win/
скачат мостбет [url=http://gtrtt.com.kg]http://gtrtt.com.kg[/url] .
deep web search https://github.com/darkwebwebsites/darkwebwebsites – dark websites darknet search engine
Привет. Может кто знает, где почитатьполезные статьи о кредитах? Пока нашел – https://autolombard626.ru
easy canadian pharm: easy canadian pharm – easy canadian pharm
online pharmacy no prescription https://xxlmexicanpharm.com/# xxl mexican pharm
darkmarket link https://github.com/darknetwebsitesgflpx/darknetwebsites – darknet market lists
drug markets dark web https://github.com/darknetwebsitesgflpx/darknetwebsites – dark market
Reasons Why Online Casinos Remain Highly Preferred Worldwide
Digital casinos have changed the betting scene, providing a unique kind of convenience and selection that conventional venues can’t match. In recent years, a large audience around the world have welcomed the fun of virtual gambling due to its anytime, anywhere convenience, exciting features, and progressively larger game libraries.
One of the biggest attractions of virtual gambling hubs is the sheer array of entertainment options available. Whether you enjoy rolling retro reel games, playing through narrative-rich visual slot games, or mastering skills in classic casino games like Blackjack, internet-based gambling sites boast countless entertainment avenues. A large number of platforms moreover feature interactive dealer games, enabling you to engage with human game hosts and opponents, all while immersing yourself in the authentic environment of a real casino without leaving your home.
If you’re unfamiliar with the world of virtual gambling or seek to explore reliable sites, why not engage with our growing online hub? It’s a hub where gamblers share stories, guiding you to enjoy more of your virtual play. Dive into the conversation and start your journey now: 1xbet
Apart from the game range, virtual gambling platforms thrive in constant connectivity.
бк мост бет http://gtrtt.com.kg/ .
1xBet – одна из ведущих компаний в сфере ставок, которая предлагает игрокам широкий выбор видов спорта и разнообразные ставки. Одним из преимуществ игры в 1xBet являются бонусные предложения, которые помогут вам увеличить свои шансы на успех и получить дополнительные выгоды https://cascadeclimbers.com/content/pgs/code_promo_melbet_bonus_de_bienvenue.html
drugmart discount drugs canadian pharmacy coupon
Hello there! Do you know if they make any plugins to safeguard against hackers?
I’m kinda paranoid about losing everything I’ve worked hard on. Any recommendations?
darkmarkets https://github.com/darknetwebsitesgflpx/darknetwebsites – darknet market links