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
Pemain bisa menikmati slot dari kenyamanan rumah http://slotdemo.auction/# Kasino di Jakarta memiliki berbagai pilihan permainan
darknet market darknet sites darknet markets url
dark web market dark markets darknet markets url
Magnificent beat ! I would like to apprentice even as you amend your web
site, how could i subscribe for a blog web site? The account aided me a appropriate deal.
I had been tiny bit familiar of this your broadcast provided bright transparent idea
http://slotdemo.auction/# Kasino di Indonesia menyediakan hiburan yang beragam
Mesin slot menawarkan pengalaman bermain yang cepat https://slotdemo.auction/# Kasino sering memberikan hadiah untuk pemain setia
It’s awesome designed for me to have a site, which is good for my know-how.
thanks admin
Incredible points. Outstanding arguments. Keep up the
amazing effort.
Mesin slot baru selalu menarik minat: bonaslot – bonaslot.site
купить аттестат в омске
bonaslot bonaslot.site Banyak pemain menikmati jackpot harian di slot
http://bonaslot.site/# Kasino sering memberikan hadiah untuk pemain setia
Appreciate the recommendation. Will try it out.
I know this site provides quality depending articles or reviews and other information, is there any other website which
provides such stuff in quality?
Mesin slot dapat dimainkan dalam berbagai bahasa http://slot88.company/# Slot menawarkan kesenangan yang mudah diakses
http://garuda888.top/# Mesin slot menawarkan pengalaman bermain yang cepat
Hello, i read your blog from time to time and i own a
similar one and i was just wondering if you get a lot of spam responses?
If so how do you reduce it, any plugin or anything you can recommend?
I get so much lately it’s driving me insane so any assistance is very much appreciated.
Kasino mendukung permainan bertanggung jawab http://slotdemo.auction/# Pemain harus menetapkan batas saat bermain
preman69.tech [url=http://preman69.tech/#]preman69.tech[/url] Slot menjadi bagian penting dari industri kasino
May I simply say what a comfort to discover someone who
truly understands what they’re discussing on the web.
You certainly realize how to bring an issue to light and make it important.
More and more people must read this and understand
this side of your story. It’s surprising you are not more popular given that you most certainly
possess the gift.
Kasino di Bali menarik banyak pengunjung https://slotdemo.auction/# Pemain sering berbagi tips untuk menang
Banyak kasino memiliki program loyalitas untuk pemain https://slot88.company/# Mesin slot digital semakin banyak diminati
This website was… how do I say it? Relevant!! Finally I’ve
found something which helped me. Appreciate it!
http://mircom200.ru/ – Кухни от производителя в Санкт-Петербурге.
Pemain sering berbagi tips untuk menang http://slotdemo.auction/# Slot memberikan kesempatan untuk menang besar
Kasino di Bali menarik banyak pengunjung: slot demo – akun demo slot
try this web-site
Fox crypto wallet
Ми знаємо як багато успіх у навчанні залежить від викладача, і спираючись на результати наших студентів та досвід, можемо з упевненістю сказати, що знаємо як ефективно викладати англійську для дітей – онлайн та офлайн. Англійська мова – це ніби магічний пароль до багатьох життєвих можливостей. З дистанційною школою «Оптіма» ваша дитина зможе його опанувати, адже вона буде навчатися в найкращого мага! Чекаємо на вас! Prometheus — найбільша платформа онлайн-освіти в Україні. У партнерстві з найкращими лекторами та провідними міжнародними організаціями вони створюють онлайн-курси з найпопулярніших тем.
https://luvly.co/users/imoperin1985
Уникайте передоплат на карту, стережіться шахраїв! Сайт не несе відповідальності за зміст оголошень, якість пропонованих товарів та послуг BIS education — офіційний партнер авторизованого тест-центру Cambridge English Language Assessment в Україні. Ви можете обрати для себе курси англійської мови онлайн або курси англійської мови у офісі освітнього центру. Репетитор німецької мови, Черкаси Здається, у вас пропав інтернет.Все знову запрацює, коли він з’явиться.
The Reasons Behind Why Online Casinos Have Become So Popular
Virtual gambling platforms have changed the casino gaming market, offering an exceptional degree of convenience and diversity that land-based venues don’t provide. Over the past decade, a large audience internationally have welcomed the adventure of online gaming in light of its availability, engaging traits, and constantly growing collections of titles.
One of the main appeals of online gaming options is the sheer range of titles provided. Whether you like engaging with retro fruit machine slots, playing through engaging video slots, or exercising tactics in card and board games like Baccarat, online platforms boast countless choices. Plenty of operators moreover offer live casino options, letting you to connect with live hosts and co-players, all while enjoying the engaging vibes of a real casino from anywhere you want.
If you’re just starting with the world of virtual gambling or are looking to learn about reputable operators, why not engage with our dynamic community? It’s a platform where players offer experiences, making it easier for you to get the most out of your casino activities. Check out the experience and learn more now: betonred casino
Adding to the extensive catalog, online casinos are known for constant connectivity.
http://slotdemo.auction/# Slot modern memiliki grafik yang mengesankan