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
en cok kazand?ran slot oyunlar?: az parayla cok kazandiran slot oyunlar? – slot tr online
Отличный сайт! Всем рекомендую!шкафы купе на заказ москва
Как официально купить диплом вуза с упрощенным обучением в Москве
Aus diesem Grund haben wir YouTube Video Downloader
entwickelt.
en cok kazand?ran slot oyunlar? slot oyunlar? puf noktalar? az parayla cok kazandiran slot oyunlar?
Стоимость дипломов высшего и среднего образования и процесс их получения
айфон про 512 цена iphone 128gb pro купить
The Most Effective Reasons For People To Succeed In The
Case Opening Battle Industry Csgo case battle
Have you ever considered about adding a little bit more than just your articles?
I mean, what you say is valuable and everything.
But think of if you added some great pictures or
video clips to give your posts more, “pop”! Your content
is excellent but with images and video clips, this website could undeniably
be one of the most beneficial in its niche. Amazing blog!
Good day! I simply wish to offer you a big thumbs up
for your excellent information you have got right here on this post.
I am coming back to your web site for more soon.
Press releases are essential for spreading news about a company’s endeavors.
They allow media outlets to cover the significant happenings.
A well-crafted press release is likely to catch
the eye of journalists, resulting in valuable press attention.
Additionally, news briefs act as an official record of information, which press agencies trust.
By crafting frequent Press distribution services Illinois [https://www.santagrand.com/user/profile/149170] communications,
corporations boost their presence within the media landscape,
building media goodwill while establishing partnerships
with news organizations.
I do consider all of the concepts you have offered for
your post. They are very convincing and can certainly work.
Nonetheless, the posts are too quick for starters.
May just you please lengthen them a little from subsequent time?
Thank you for the post.
Thanks , I have just been searching for information approximately this topic for a while
and yours is the best I have found out till now.
However, what concerning the conclusion? Are you positive in regards to the supply?
Узнайте стоимость диплома высшего и среднего образования и процесс получения
Пошаговая инструкция по безопасной покупке диплома о высшем образовании
Thanks for sharing your thoughts on Techtunes Auto. Regards
Покупка диплома о среднем полном образовании: как избежать мошенничества?
good-serial.ru/2024/10/diplom-po-lyuboy-spetsialnosti-kak-kupit
15 Reasons Why You Shouldn’t Overlook Wall Mount Electric Fireplaces wall
electric fires – Troy,
I for all time emailed this weblog post page to all my contacts,
because if like to read it afterward my friends will too.
Официальное получение диплома техникума с упрощенным обучением в Москве
красная поляна прокат горнолыжного снаряжения цена аренда лыжи сочи
Does Technology Make Fiat 500 Replacement Key Cost Better Or
Worse? chip
slot tr online: slot oyunlar? puf noktalar? – en cok kazand?ran slot oyunlar?
http://matadorbet.bid/# matadorbet
denemebonusuverensiteler.top
This is a topic that’s close to my heart… Best wishes! Where are your contact details though?
Официальная покупка диплома вуза с сокращенной программой обучения в Москве
14 Clever Ways To Spend The Leftover Wall Fireplace Electric Budget Tabletop Fireplace
The Leading Reasons Why People Perform Well
On The Online Mystery Box Industry online mystery box websites
guvenilir casino siteleri Deneme Bonusu Veren Siteler Canl? Casino Siteleri
Medication information for patients. Drug Class.
buying generic esomeprazole without rx
Best what you want to know about medicine. Read information now.