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
dark websites https://github.com/tormarkets2025ukaz1/tormarkets2025 – dark web market
1Win casino Lucky Jet game Colombia
Howdy would you mind letting me know which webhost you’re utilizing?
I’ve loaded your blog in 3 completely different
internet browsers and I must say this blog loads a lot faster then most.
Can you suggest a good web hosting provider at a
fair price? Thanks, I appreciate it!
darkmarket list https://github.com/darkmarketlinkp22jr/darkmarketlink – darknet market lists
dark market https://github.com/darknetdruglinksvojns/darknetdruglinks – darknet sites
dark market https://github.com/darkwebwebsites/darkwebwebsites – dark web sites darknet market
deep web drug url https://github.com/darknetmarkets2025/darknetmarketlinks – tor market links deep web markets
drug markets onion https://github.com/darkwebwebsites/darkwebwebsites – deep web sites darknet market links
canadian online pharmacy no prescription https://discountdrugmart.pro/# mail order prescription drugs from canada
deep web search https://github.com/darknetmarkets2025/darknetmarketlinks – how to get on dark web dark web links
easy canadian pharm: easy canadian pharm – canadianpharmacyworld com
Hey there would you mind letting me know which hosting company you’re
using? I’ve loaded your blog in 3 completely different internet browsers and
I must say this blog loads a lot faster then most. Can you suggest
a good hosting provider at a honest price? Kudos, I appreciate it!
1win.online скачать [url=http://bbcc.com.kg]http://bbcc.com.kg[/url] .
darknet market https://github.com/darknetmarketslinks/darknetmarketlinks – dark internet darkweb marketplace
plataforma 1win https://bbcc.com.kg .
canadian pharmacy world coupons https://megaindiapharm.com/# Mega India Pharm
buy viagra online
deep web drug links https://github.com/darknetmarketslinks/darknetmarketlinks – tor marketplace darknet markets 2025
https://bodyrslm.ru – Кухни от производителя в Санкт-Петербурге.
best canadian pharmacy no prescription http://discountdrugmart.pro/# discount drug pharmacy
Pharmacie en ligne, Acheter Cialis, Acheter Viagra, Acheter Kamagra. Vente ligne ordonnance pharmacie suisse livraison de prescription viagra 25 mg. Achat de cialis pas cher, cialis generique en pharmacie, Arubahuis. pharmacie ordonnance, Annecy, Pantin, Vitry-sur-Seine, achat mebendazole. en ligne inde cipla.Acheter tadalafil en ligne de lInde. Viagra 50 mg, viagra acheter en pharmacie, Jerseycityindependent. https://eurogeneriqueetfrance.com/lamictal/ Generique Lamictal Alternative
1xBet provides a wide array of bonuses and promotions for its customers in 2025. These offerings include welcome bonuses, reload bonuses, cashback bonuses, and more. The welcome bonus is typically available to new customers making their first deposit, while reload bonuses cater to existing customers who make additional deposits https://asmibmr.edu.in/news/1xbet_promo_code___welcome_bonus_130.html
Привет. Может кто знает, где найтиразные блоги о кредитах? Пока нашел – https://kreditvpermi.ru
foreign pharmacy no prescription http://easycanadianpharm.com/# the canadian drugstore
как выводить деньги с 1win bbcc.com.kg .
1win сайт вход https://bbcc.com.kg .
What Makes Online Casinos Remain a Worldwide Trend
Virtual gambling platforms have reshaped the gambling market, offering a level of accessibility and range that conventional casinos don’t provide. Throughout the last ten years, a large audience internationally have welcomed the thrill of virtual gambling because of its accessibility, captivating elements, and progressively larger selection of games.
One of the key draws of online casinos is the unparalleled selection of gaming experiences provided. Whether you love interacting with retro one-armed bandits, playing through theme-based video-based games, or playing smart in strategy-based games like Texas Hold’em, internet-based gambling sites provide infinite choices. Many casinos furthermore introduce live dealer games, letting you to engage with human game hosts and opponents, all while taking in the immersive environment of a traditional gambling venue without leaving your home.
If you’re a beginner with the world of online gaming or are looking to delve deeper into trusted platforms, why not become part of our growing gaming forum? It’s a platform where enthusiasts post reviews, assisting you to get the most out of your gaming journey. Join the experience and start your journey now: betonred casino avis
Adding to the extensive catalog, virtual gaming providers stand out accessibility.
вход 1win http://www.bbcc.com.kg .
кухни на заказ спб – Закажите кухни в Санкт-Петербурге по индивидуальным проектам.
tor darknet https://github.com/darknetmarketslinks/darknetmarketlinks – onion market darknet websites