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
darkmarkets https://github.com/darkwebmarketslinks/darkwebmarkets – deep web drug links darkmarket
easy canadian pharm: canadian pharmacy online store – easy canadian pharm
bokep terbaik sma toket gede menyala banget
1 win casino http://www.bbcc.com.kg .
Nice blog here! Additionally your site rather a lot up very fast!
What host are you using? Can I am getting your affiliate hyperlink for your host?
I wish my website loaded up as fast as yours lol
buying cheap clomid for sale can i buy clomid without dr prescription get generic clomid prices
can you buy generic clomid no prescription cost of cheap clomid pill buying clomid no prescription
can i buy cheap clomid without insurance
where to get clomid without a prescription where buy clomid prices where to get cheap clomid
buying cheap clomid without insurance buy generic clomid for sale can i buy cheap clomid tablets
Проблема зависимостей остаётся актуальной в современном обществе. С каждым годом увеличивается число людей, страдающих от алкоголизма, наркомании и других форм зависимостей, что негативно отражается на их жизни и благополучии близких. Зависимость — это не просто физическое заболевание, но и глубокая психологическая проблема. Для эффективного лечения требуется помощь профессионалов, способных обеспечить комплексный подход.
Ознакомиться с деталями – вывод из запоя круглосуточно воронеж
darknet site https://github.com/darkwebmarketslinks/darkwebmarkets – dark web market links deep web drug markets
MIKIGAMING menyediakan game slot online modern dengan bonus istimewa, grafis tajam, dukungan dan proteksi optimal untuk pengalaman bermain terbaik
xxl mexican pharm: mexico pharmacies prescription drugs – mexican pharmaceuticals online
Всем привет! Подскажите, где почитатьполезные статьи о кредитах? Пока нашел – https://kredit-taxi.ru
1 win вход fabc.com.kg .
cheapest pharmacy for prescriptions without insurance http://familypharmacy.company/# canadian pharmacy world coupons
drug markets onion https://github.com/tormarkets2025ukaz1/tormarkets2025 – dark market 2022
darknet markets 2025 https://github.com/darknetmarketslinks/darknetmarketlinks – drug markets dark web darknet sites
Glass Window Repair Near Me The Process Isn’t As
Hard As You Think Repair Broken Window Glass Near Me; Kingranks.Com,
There is definately a lot to find out about this topic.
I really like all the points you’ve made.
dark web sites https://github.com/darknetmarketlinks2025/darknetmarkets – darkweb marketplace
easy canadian pharm: canadian online pharmacy reviews – canada drugs reviews
darknet market list https://github.com/darknetmarketslinks/darknetmarketlinks – dark market link dark market onion
Write more, thats all I have to say. Literally, it seems as though you relied on the video to make your point.
You obviously know what youre talking about, why throw away your intelligence on just
posting videos to your site when you could be giving us something informative to read?
Долго искал инструмент для пассивного дохода, который будет сочетать стабильность, прозрачность и безопасность. UTLH оказался именно тем, что нужно! Стейкинг даёт 2% в месяц, причём без каких-то сложных условий. Всё просто: закинул токены, ждёшь — и получаешь доход. Уже несколько месяцев пользуюсь, выплаты приходят вовремя, и сам токен потихоньку растёт в цене. Надёжный проект с сильным комьюнити, приятно быть его частью.
mostbet aplikace http://www.gtrtt.com.kg .
Reasons Why Online Casinos Are So Popular
Online casinos have changed the gaming landscape, delivering an unmatched level of accessibility and diversity that physical establishments can’t match. Recently, millions of players globally have adopted the excitement of online gaming due to its always-open nature, thrilling aspects, and progressively larger game libraries.
One of the most compelling reasons of virtual gambling hubs is the sheer selection of choices ready to play. Whether you are a fan of spinning traditional fruit machine slots, playing through engaging video slots, or strategizing in strategy-based games like Roulette, casino websites boast limitless possibilities. Numerous services also feature interactive dealer games, letting you to engage with human game hosts and fellow gamblers, all while enjoying the engaging atmosphere of a physical gaming house from anywhere you want.
If you’re a beginner with the world of virtual gambling or want to learn about reliable sites, why not join our growing community? It’s a hub where fans offer experiences, guiding you to enhance your online casino experience. Dive into the experience and see it here now: verde casino no deposit bonus
Apart from the game range, online casinos thrive in availability.
online pharmacy prescription https://easycanadianpharm.shop/# easy canadian pharm
https://free-4306800.webador.com/
canada online pharmacy no prescription https://xxlmexicanpharm.com/# mexican mail order pharmacies
A knowledgeable mind Head Injury Attorney Florida lawyer might have the ability to help.
dark web link https://github.com/tormarkets2025ukaz1/tormarkets2025 – tor marketplace
dark market https://github.com/darknetmarkets2025/darknetmarketlinks – tor markets links tor marketplace