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
The mind brain injury attorney in nyc attorneys at DE CARO & KAPLEN, LLP.
The rise of online casinos has revolutionized the gambling industry, making it more accessible, convenient, and thrilling than ever before. Now, gamblers don’t have to travel to experience the thrill of betting, as the full casino experience is accessible from desktops, tablets, and smartphones.
The Appeal of Online Gambling
There are many reasons why online casinos have gained massive traction. Perhaps the most appealing aspect is how easy it is to access games. While land-based casinos have restrictions, internet-based casinos never close, ensuring round-the-clock entertainment.
Another major reason for their popularity is the sheer variety of games. While land-based venues have space constraints, online casinos provide an endless assortment of games. From classic fruit machines to cutting-edge video slots with immersive themes, the choices are practically limitless.
Stay updated with the latest casino news, exclusive bonuses, and expert tips—follow us aviator
Bonuses, Rewards, and Promotions
Bonuses and special offers make online gambling even more enticing. Signing up usually comes with exciting perks like extra cash or free slot spins. Loyal customers are rewarded with tiered programs, reloading bonuses, and special incentives.
Choosing Between Luck-Based and Skill-Based Games
Depending on your preferences, you can choose between pure chance games or those where skill makes a difference. For those who enjoy strategic play, poker offers opportunities to refine skills and increase winning chances. On the other hand, slot machines and roulette rely entirely on chance, making them ideal for casual players looking for fun and excitement.
How to Gamble Responsibly Online
While online casinos offer fun and potential winnings, responsible gambling is crucial. Smart bankroll management and self-control help players maintain a healthy approach to gambling. Licensed casinos provide responsible gambling measures, such as cooling-off periods and withdrawal restrictions, to help players stay in control.
Share Your Casino Experience
Are you an online casino enthusiast? What’s your go-to game? Drop your opinions and stories in the discussion thread!
вход в 1win https://bbcc.com.kg .
гинеколог порно гинеколог порно .
darknet drug store https://github.com/darknetdruglinksvojns/darknetdruglinks – dark web links
mostbet сайт gtrtt.com.kg .
мульт порно мульт порно .
payday loan
1win pro http://fabc.com.kg .
1win сайт вход http://fabc.com.kg .
порно гинеколог порно гинеколог .
MegaIndiaPharm: Mega India Pharm – MegaIndiaPharm
cheapest pharmacy prescription drugs http://familypharmacy.company/# Online pharmacy USA
1 wim http://bbcc.com.kg/ .
Reasons Why Online Casinos Are Highly Preferred Worldwide
Internet-based gambling hubs have reshaped the gambling industry, providing a level of convenience and breadth that physical venues don’t provide. Throughout the last ten years, a growing community worldwide have embraced the pleasure of online gaming because of its availability, captivating elements, and widening collections of titles.
One of the strongest selling points of online gaming options is the sheer variety of choices provided. Whether you enjoy interacting with classic one-armed bandits, immersing yourself in theme-based video slots, or strategizing in classic casino games like poker, online platforms deliver endless choices. Plenty of operators additionally include interactive dealer games, allowing you to connect with live hosts and fellow gamblers, all while immersing yourself in the authentic environment of a land-based casino in your own space.
If you’re a beginner with the world of digital casinos or want to explore safe services, why not become part of our lively gaming forum? It’s a destination where players exchange experiences, guiding you to enhance your gambling adventure. Check out the discussions and see it here now: verde casino no deposit bonus
Apart from the game range, virtual gaming providers excel seamless entry.
canadianpharmacymeds com: certified canadian pharmacy – canadianpharmacyworld com
мультики порно мультики порно .
Привет. Может кто знает, где почитатьразные статьи о кредитах? Сейчас читаю – https://taxandlex.ru
мультики порно мультики порно .
Hello! I simply would like to give you a big thumbs up for the great info you have got right here on this post.
I am returning to your web site for more soon.
порно гинеколог порно гинеколог .
you’re in point of fact a good webmaster. The web site loading pace is amazing.
It sort of feels that you are doing any unique trick.
Moreover, The contents are masterwork. you’ve performed a excellent
process in this topic!
online pharmacy no prescription needed http://familypharmacy.company/# online pharmacy delivery usa
Best online pharmacy: Cheapest online pharmacy – family pharmacy
1win pro http://bbcc.com.kg/ .
секс мультики секс мультики .
deep web drug store https://github.com/darknetmarketslinks/darknetmarketlinks – dark web sites links darknet drug links
Mega India Pharm: cheapest online pharmacy india – MegaIndiaPharm
cheapest pharmacy for prescriptions http://discountdrugmart.pro/# discount drugs
discount drugs drug mart drug mart