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
הנשים הטובות ביותר לעיסוי ואהבה לוהטת ללא גבולות. בחורות מושלמות לעיסוי אידיאלי כל אזור הצפון ידועה לא רק בזכות הבניינים בשביל הפעילות הרומנטית. בדירות תמיד תמצאו מיטה גדולה ובה מצעים נקיים, דבר המאפשר לכם לבלות בנעימים. וכאשר העניינים מתחילים שירותי סקס
Nicely put, Many thanks.
Well expressed certainly! !
Excellent post. I certainly appreciate this site. Continue the good work!
15 Reasons Not To Be Ignoring Slot Missions Top Mobile Slots
The Reasons To Focus On Improving Slot Symbols slot strategy (Maxwell)
How To Research Starlight Princess Online Demo Slot Starlight Princess Rupiah
I’ve been browsing online more than 2 hours today,
yet I never found any interesting article like yours.
It is pretty worth enough for me. In my view, if all site
owners and bloggers made good content as you did, the internet will be a lot more useful
than ever before.
You have got the most effective web pages.
https://www.swiebodzin.tv
The Most Effective Classic Slots Tips To Transform Your Life
Best payouts Slots
Online Shopping Uk Electronics Techniques To Simplify Your Daily Lifethe One
Online Shopping Uk Electronics Trick That Everybody Should Be Able To online shopping uk electronics (Tracy)
Здесь вы найдете разнообразный видео контент Ялта Видео,
охватывающий множество платформ и форматов.
От коротких зрелищных роликов на
TikTok до долгоиграющих трансляций на Twitch – мой канал стремится объединить лучшее из разных миров видео.
Присоединяйтесь, чтобы веселиться вместе с потоковым мультимедиа Stream, наслаждаться премиум-контентом
от Vevo и Vimeo, а также открывать для себя новые таланты на Rumble и BitChute.
Также вы найдете здесь эксклюзивный контент для
Instagram TV (IGTV), Facebook Watch и других социальных платформ.
А для поклонников аниме есть отдельная секция с лучшим контентом от Crunchyroll.
Используя мощь профессиональных инструментов, таких как
Brightcove, Kaltura, JWPlayer, IBM Cloud Video и многих других,
я стараюсь предоставить вам впечатляющий и высококачественный видео
опыт.
Подписывайтесь сегодня и оставайтесь на
волне самого свежего и разнообразного видео контента в интернете.
Добро пожаловать в мой мир ярких видео!”
Это описание канала объединяет все упомянутые вами видео платформы, демонстрируя вашу готовность работать с разными форматами и обеспечивать качественный и разнообразный контент для зрителей. Пусть оно привлечет новых подписчиков!
What Is Bmw Key Fob And How To Utilize It bmw spare key fob
5 Killer Quora Answers On Demo Hades Demo Hades
Hi there to all, how is everything, I think every one
is getting more from this web site, and your views are pleasant
in support of new people.
What’s up to every one, the contents existing at this website
are actually remarkable for people knowledge, well, keep up the good work
fellows.
It’s wonderful that you are getting ideas from this article as well as from our argument made here.
my page mattress
Why Is There All This Fuss About Online Shopping Sites List For Clothes?
Large Coffee Frame Wooden
10 No-Fuss Methods For Figuring Out Your High Roller Slots slot providers (https://www.instapaper.com/p/14369815)
10 Tips For Getting The Most Value From Online Shopping Uk Groceries Permanent Adhesive Roller
10 No-Fuss Ways To Figuring Out Your Shopping Online shopping online Sites clothes
Your data is very significant.
https://gwe24.pl/pl/
Slot Demo 10 Things I’d Love To Have Known Sooner demo slot Gates of olympus indonesia
Famous French footballer Kylian Mbappe https://kylianmbappe.prostoprosport-ar.com has become a global ambassador for Dior. The athlete will represent the men’s collections of creative director Kim Jones and the Sauvage fragrance, writes WWD. Mbappe’s appointment follows on from the start of the fashion house’s collaboration with the Paris Saint-Germain football club. Previously, Jones created a uniform for the team where Kylian is a player.
The Most Sour Advice We’ve Ever Seen About Slot Sites
Slot Sites best Online slots
Hi there! I’m at work surfing around your blog from my new iphone 3gs!
Just wanted to say I love reading through your blog
and look forward to all your posts! Keep up the fantastic work!
Medicament information leaflet. What side effects can this medication cause?
can i buy seroquel online
Some what you want to know about meds. Get information now.
The Reason Why Examples Of Online Products Is The Most Popular Topic In 2023 Tw108 Fan
Don’t Make This Silly Mistake With Your Slot Reviews
slot machine reviews (Blythe)
I am really loving the theme/design of your blog. Do you ever run into any web browser
compatibility issues? A handful of my blog audience have complained
about my website not operating correctly in Explorer
but looks great in Firefox. Do you have any suggestions to help fix this issue?
Have a look at my blog post – ครีมกันแดด