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
ozempic cost: Ozempic without insurance – ozempic coupon
Hi, I do think this is an excellent website. I stumbledupon it 😉 I may return once again since i have book-marked it.
Money and freedom is the greatest way to change, may you be
rich and continue to guide other people.
Наш этношоп НашаМебель зовет широченный запас кухонь, коим посодействуют создать устроенность (а) также благоустроенность в течение вашем доме https://notahye4kuhnishki.ru/.
Официальный сайт R7 Casino. Зарегистрируйтесь и получите приветственные бонусы. Играйте в лучшие игровые автоматы, участвуйте в турнирах и выигрывайте раменбет зеркало
rybelsus price: buy rybelsus online – buy rybelsus online
20 Resources That Will Make You More Efficient With Toto4d Toto online terbaik
http://rybelsus.shop/# semaglutide tablets
Seven Submitting Of Social Bookmarks Tips For Webmasters
링크모음 (dahan.com.tw)
10 Facts About Togel4d That Can Instantly Put You
In An Optimistic Mood situs Togel online
rybelsus cost: cheapest rybelsus pills – semaglutide cost
10 Quick Tips For Porsche Cayenne Spare Key Repair
Hello! I understand this is somewhat off-topic but I had to ask.
Does managing a well-established blog like yours take a lot of work?
I am brand new to writing a blog but I do write in my journal on a daily basis.
I’d like to start a blog so I will be able to share my
experience and feelings online. Please let me know if you
have any recommendations or tips for new aspiring blog owners.
Thankyou!
https://ozempic.art/# ozempic coupon
I got this web page from my pal who told me on the topic of this website and now this time I am browsing this site and reading very informative
content at this time.
Looking for the best online betting experience in Ghana?
Welcome to **1win**, your go-to platform for all things sports betting, casino games, and more.
At 1win, we offer a comprehensive and exciting environment for both new and experienced
bettors, ensuring you get the most out of your gaming experience.
### Why Choose 1win Ghana?
1. **Extensive Betting Markets**: At 1win, we cover a wide
range of sports, including football, basketball, tennis, and more.
You can bet on local and international tournaments, with competitive odds that
increase your chances of winning big.
2. **Live Betting**: Want to bet on a match while it’s happening?
Our live betting feature lets you place wagers
in real-time, adding an extra layer of excitement to your sports watching
experience. Track the game’s progress and place strategic bets
as the action unfolds.
3. **Diverse Casino Games**: If you’re looking for more than just sports betting, our online casino has a
rich selection of games. From classic slots and table games like blackjack and roulette to live dealer games,
you’ll find endless entertainment options.
4. **User-Friendly Interface**: The 1win platform
is designed with simplicity in mind, making it easy for users to navigate.
Whether you’re accessing the platform via desktop or mobile,
you’ll find it easy to place bets, explore casino games, and manage your
account.
5. **Attractive Bonuses**: At 1win, we believe in rewarding
our users. We offer a generous welcome bonus for new
players, regular promotions, and exciting rewards to keep the thrill alive.
Make sure to check our promotions page to stay updated on the latest
offers.
6. **Safe and Secure**: We prioritize the safety of our users, which is why 1win uses state-of-the-art encryption technology to protect your personal information and transactions.
Bet and play with peace of mind, knowing that your data is secure.
7. **Easy Deposit and Withdrawal Options**: 1win Ghana offers multiple payment methods tailored to the preferences of local users.
Whether you’re using mobile money, bank transfers, or
e-wallets, we’ve got you covered with fast and hassle-free
transactions.
### How to Get Started
1. **Register**: Signing up is simple! Just visit our website, click on the “Register”
button, and fill in your details. Once your account is created, you can start exploring all the features 1win has to offer.
2. **Make a Deposit**: Fund your account using one of our convenient payment options.
With your deposit in place, you’re ready to
start betting or playing casino games.
3. **Start Betting**: Browse through our wide selection of sports events or dive into
our casino for hours of entertainment. Remember to keep an eye on live games for
dynamic betting opportunities.
4. **Withdraw Your Winnings**: When you’re ready to cash out, simply head to the withdrawal section, select your
preferred method, and enjoy quick payouts with no fuss.
### Join 1win Ghana Today!
Don’t miss out on the best online gaming experience.
Sign up with **1win Ghana** today to enjoy world-class sports betting, exciting casino games, and a wide array of rewards and bonuses.
Whether you’re a seasoned player or just starting, 1win is the perfect platform to take your
gaming to the next level.
“https://gratisafhalen.be/author/harrishvo39/”
https://ozempic.art/# ozempic coupon
Thanks for ones marvelous posting! I quite enjoyed reading it, you’re a great author.
I will make sure to bookmark your blog and may come
back in the future. I want to encourage yourself
to continue your great work, have a nice day!
buy ozempic: ozempic coupon – ozempic coupon
https://ozempic.art/# buy ozempic
buy cheap ozempic: buy cheap ozempic – ozempic cost
My spouse and I stumbled over here different page and thought I might as well check
things out. I like what I see so i am just following
you. Look forward to going over your web page for a second time.
Hi there! Someone in my Facebook group shared this website with us so I came to look it over.
I’m definitely loving the information. I’m book-marking and will be tweeting this to my followers!
Excellent blog and excellent design.
This article deserves a wider audience.오피
cheapest rybelsus pills: semaglutide tablets – rybelsus price
semaglutide cost: semaglutide tablets – rybelsus coupon
Hey there! This is my 1st comment here so I just wanted to give a quick shout out and say I genuinely enjoy
reading your blog posts. Can you suggest any other blogs/websites/forums that cover the same topics?
Thank you!
**1win Togo: Votre Destination de Paris en Ligne Fiable et Innovante**
Bienvenue sur **1win Togo**, votre plateforme de paris en ligne de confiance, où l’innovation rencontre la simplicité pour vous
offrir la meilleure expérience de jeu possible. Que vous soyez un amateur de
paris sportifs, un passionné de casino ou un joueur occasionnel cherchant du divertissement, 1win Togo vous propose une large gamme d’options pour satisfaire toutes vos envies de jeu.
### Une Plateforme de Paris Sportifs Diversifiée
Chez 1win Togo, nous comprenons l’importance de la diversité pour les parieurs sportifs.
C’est pourquoi nous couvrons un large éventail de sports :
football, basketball, tennis, rugby, et bien d’autres.
Vous pouvez parier sur vos équipes et événements favoris, que ce soit à
l’échelle nationale ou internationale.
– **Des cotes compétitives** : Nous offrons des cotes parmi les plus attractives du marché pour maximiser vos gains.
– **Une interface intuitive** : Notre plateforme est facile à utiliser, que vous soyez un parieur expérimenté
ou débutant. Placez vos paris rapidement et en toute sécurité.
### Un Casino En Ligne Exceptionnel
Si vous préférez l’univers des casinos en ligne, **1win Togo** met à votre disposition une
vaste collection de jeux de casino. Des machines à
sous modernes aux jeux de table classiques comme la roulette, le blackjack et le poker, chaque joueur trouvera quelque chose à son goût.
– **Machines à sous à jackpot** : Tentez votre chance sur nos machines à sous à jackpot progressif
et décrochez des gains incroyables.
– **Jeux en direct** : Pour une expérience plus immersive, profitez de nos jeux en direct avec des croupiers professionnels.
### Pourquoi Choisir 1win Togo ?
1. **Sécurité et fiabilité** : Nous mettons un point d’honneur à assurer la
sécurité de vos données personnelles et de vos transactions.
Nos systèmes sont hautement sécurisés pour garantir une expérience
de jeu sans souci.
2. **Promotions et bonus attractifs** : Chez **1win Togo**, chaque nouveau
joueur bénéficie de généreux bonus de bienvenue,
ainsi que de nombreuses promotions régulières pour nos membres existants.
3. **Support client réactif** : Notre équipe d’assistance est disponible 24/7
pour répondre à toutes vos questions et vous aider à résoudre vos préoccupations rapidement.
### Inscription Facile et Rapide
Rejoindre **1win Togo** est simple et rapide. En quelques
minutes, vous pourrez créer votre compte, effectuer votre premier dépôt et commencer à jouer.
Notre processus d’inscription est conçu pour être fluide afin que vous puissiez profiter de l’action sans attendre.
**Ne perdez plus de temps !** Rejoignez la communauté 1win Togo dès aujourd’hui et découvrez un monde de divertissement, de paris sportifs et de jeux de casino,
avec des chances de gagner des récompenses excitantes à
chaque instant.
“https://fishtanklive.wiki/User:AdrienneAnders”
Hey very nice blog!
Feel free to surf to my homepage :: building construction services
7 Things You’d Never Know About Depression Treatment Programs depression treatment centers
Как улучшить настроение другу? Посмотрите
прикольные анекдоты и поделитесь с близкими.