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
Добро пожаловать в Booi Casino – место, где азарт и увлекательные игры встречаются с большими победами. В нашем казино есть всё, что нужно для настоящих азартных игроков – от слотов до живых игр с профессиональными дилерами. В Booi Casino мы ценим доверие наших игроков и обеспечиваем безопасную и честную игровую среду.
Почему стоит выбрать Booi Casino? С нами вы можете быть уверены в быстроте выплат и надежности всех транзакций. Наши бонусы, акции и эксклюзивные предложения создадут незабываемые впечатления от игры.
Когда лучше начать свой путь к большим победам в Booi Casino? Присоединяйтесь к нам прямо сейчас и воспользуйтесь всеми преимуществами казино. Вот что ждёт вас:
Получите щедрые бонусы на первый депозит и начните играть с дополнительными возможностями.
Периодические турниры с невероятными призами.
Каждый месяц мы обновляем нашу коллекцию игр, добавляя новинки и популярные слоты.
Booi Casino – это ваш шанс испытать удачу и стать победителем. https://booi-gamestorm.monster/
reliable mexican pharmacies buying from online mexican pharmacy buying from online mexican pharmacy
This is very interesting, You are a very skilled blogger.
I have joined your feed and look forward to seeking more of your fantastic post.
Also, I’ve shared your web site in my social networks! https://Classifieds.Ocala-News.com/author/dannykingsf
my canadian pharmacy Inter Pharm Online legitimate canadian pharmacies
I got this website from my friend who told me concerning this site and
now this time I am visiting this website and reading very informative articles at this place.
Hello to all, how is everything, I think every one is getting more
from this web page, and your views are pleasant designed for new visitors.
Very good advice, Cheers!
Feel free to visit my page :: http://cqcici.com/comment/html/?418846.html
https://indiamedfast.com/# IndiaMedFast.com
canadapharmacyonline
I don’t know if it’s just me or if perhaps everybody else encountering issues with
your site. It appears as if some of the text within your content
are running off the screen. Can someone
else please provide feedback and let me know if this is happening to them as
well? This might be a problem with my web browser because I’ve had this happen before.
Cheers
Digital casinos have changed the gambling landscape, delivering a unique kind of accessibility and range that conventional casinos don’t provide. Over time, a vast number of enthusiasts across the globe have chosen the fun of online gaming thanks to its ease of access, appealing qualities, and ever-expanding range of offerings.
If you’re new with the world of virtual gambling or want to explore safe services, why not engage with our dynamic gaming forum? It’s a place where gamblers post stories, guiding you to maximize your gaming journey. Join the discussions and see it here now: https://bbs.flashdown365.com/home.php?mod=space&uid=1794861&do=profile&from=space
One of the most compelling reasons of internet-based platforms is the incredible range of gaming experiences on offer. Whether you like engaging with old-school slot machines, exploring theme-based modern slot games, or exercising tactics in table games like Roulette, virtual venues deliver limitless entertainment avenues. A large number of platforms also present real-time gaming experiences, making it possible for you to interact with real dealers and other players, all while immersing yourself in the immersive feel of a land-based casino from the comfort of your home.
Apart from the game range, internet-based gambling hubs are known for seamless entry.
Информация о раскрутке сайта в СПб
https://mexicanpharminter.com/# Mexican Pharm International
canada pharmacy 24h
reliable mexican pharmacies mexican pharmacy online buying from online mexican pharmacy
https://mexicanpharminter.com/# reliable mexican pharmacies
reliable canadian online pharmacy
https://mexicanpharminter.com/# Mexican Pharm Inter
canada discount pharmacy
darknet markets 2025 https://github.com/darkwebsitesyhshv/darkwebsites – darkmarkets
mexican pharmacy online order: Mexican Pharm International – mexican pharmacy online
Thank you, I’ve recently been looking for information about this topic for ages and yours is the best I’ve came upon so far.
However, what in regards to the conclusion? Are you sure in regards to the source?
darknet links https://github.com/aresonioncq0a7/aresonion – darknet market list
cheapest online pharmacy india order medicines online india india pharmacy without prescription
https://indiamedfast.shop/# cheapest online pharmacy india
read the article zkLogin sui
I loved as much as you’ll receive carried out right here.
The sketch is tasteful, your authored subject matter stylish.
nonetheless, you command get got an nervousness over
that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly a lot often inside case you shield this
increase.
I was pretty pleased to uncover this site. I wanted to thank you
for ones time for this fantastic read!! I
definitely savored every bit of it and i also have you saved to fav to look at new information in your
web site.
mexican pharmacy online: buying from online mexican pharmacy – mexican pharmacy online
buying prescription drugs from india: lowest prescription prices online india – india online pharmacy store
online medicine shopping in india: india online pharmacy store – India Med Fast
My coder is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the expenses. But he’s tryiong none the less.
I’ve been using WordPress on numerous websites for about a year and
am concerned about switching to another platform. I have
heard good things about blogengine.net. Is there a way
I can transfer all my wordpress posts into it? Any kind of help would be really appreciated!
lowest prescription prices online india: online medicine shopping in india – order medicines online india
http://interpharmonline.com/# canadian pharmacy online store