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
TadalafilEasyBuy.com Tadalafil Easy Buy п»їcialis generic
Buy generic 100mg Viagra online viagra canada Generic 100mg Easy
Feel free to visit my page: dating sites for over 50 (mabietodd.co)
Feel the adrenaline of playing at 4rabet with seamless access through 4rabet login . Whether you enjoy 4 ra bet sports betting or virtual casino action, this site provides everything under one roof. Download the 4rabet application for quick and easy access to your favorite games . Explore the 4rabet official website now and dive into the thrill of 4rabet . Register now and enhance your casino fun to the highest peak !
Discover the thrill of the 4rabet platform , your best site for sports betting and thrilling bets in India. Whether you’re a fan of football or different events , the official 4rabet platform offers a seamless platform to enjoy betting and maximize your profits. With the 4rabet app login , you can log in to your betting profile at any moment, anywhere , ensuring you don’t lose a chance . The 4ra bet platform is designed for both first-time users and seasoned players , featuring a vast collection of wagering opportunities and casino games .
Register with the growing 4rabet family today and experience a secure , easy-to-use betting system. Whether you like using 4rabet on your PC or mobile , the online casino fun is second to none . Kick off your betting experience with 4 ra bet and take your sports betting journey to the ultimate thrill!
Link: https://bizbuzzmag.org/android-4rabet-how-to-download-the-app/
4rabet India brings a easy process for online gambling and gamblers in India. With the easy account access process being hassle-free and secure , players can access their betting dashboards in seconds . The smartphone access ensures accessibility for mobile users , making it easy to bet anytime, anywhere . 4rabet India offers a wide range of wagering opportunities , including cricket , and many other games , catering to Indian audiences. The website is user-friendly , simplifying the experience for both beginners and high-stakes users to use . By checking out the main site , members can claim special promotions. The 4ra bet platform is known for its reliability and instant cashouts, ensuring a trustworthy online gambling journey. Whether you enjoy sports betting or live dealer experiences, our platform has something for everyone .
pinup 2025: https://pinupkz.life/
пин ап казино зеркало – пин ап казино официальный сайт
What’s Taking place i am new to this, I stumbled upon this
I have discovered It absolutely useful and it has aided me out loads.
I hope to contribute & help different users like its aided me.
Good job.
I like reading through a post that will make people think.
Also, many thanks for permitting me to comment!
пин ап – пин ап
Very nice post. I just stumbled upon your weblog and wished to say that I’ve really enjoyed surfing around
your blog posts. After all I will be subscribing to your rss feed and I hope you write again very soon!
Tadalafil Easy Buy Tadalafil Easy Buy TadalafilEasyBuy.com
darknet site dark markets
best online pharmacy
pinup 2025: https://pinupkz.life/
Enjoy the thrill of 4rabet online gaming with seamless access through your 4rabet account . Whether you love sports wagering on 4rabet or casino games , our platform offers it all on one site . Install the 4rabet app login for instant and seamless gaming to your favorite games . Check out the 4rabet homepage today and explore the thrill of 4rabet . Join 4 bet and take your casino fun to the ultimate thrill!
Discover the adrenaline rush of online gaming with 4rabet, your ultimate platform for wagering on sports and casino games in India. Whether you love football or other popular sports , the main 4rabet site features a easy-to-use interface to enjoy betting and win big . With the 4rabet application, you can log in to your player dashboard 24/7 , wherever you are, guaranteeing you never miss out . The 4ra bet platform is made for both beginners and seasoned players , offering a wide range of betting options and casino games .
Become a part of the growing 4rabet family now and immerse yourself in a secure , easy-to-use betting system. Whether you like accessing your account on your desktop or mobile , the 4rabet betting journey is top-tier. Start your journey with 4rabet India and upgrade your gaming experience to new heights !
Link: https://celsius.justbelowthehorizon.com/2016/06/03/youtube-post/
The 4rabet platform brings a seamless process for online gambling and casino fans in India. With the 4rabet login process being fast and protected , users can log into their accounts effortlessly . The mobile login feature guarantees accessibility for mobile users , allowing them to bet anytime, anywhere . 4rabet India provides a wide range of sports events, including football , and other major sports, designed for Indian bettors . The 4rabet online platform is easy to navigate , making it easy for both beginners and high-stakes users to enjoy. By checking out the 4rabet official website , members can enjoy exclusive promotions. The 4rabet casino is famous for its reliability and instant cashouts, ensuring a satisfying gaming experience . Whether you enjoy gambling on matches or playing slots , our platform has something for everyone .
I’m not certain where you’re getting your info, however
good topic. I needs to spend some time finding out much more or working out more.
Thanks for fantastic info I was on the lookout for
this info for my mission.
buy viagra online
пин ап казино зеркало – пин ап зеркало
buy generic 100mg viagra online Generic100mgEasy Generic100mgEasy
1win betting site https://www.1win12.com.ng .
TadalafilEasyBuy.com cialis without a doctor prescription cialis without a doctor prescription
Ꭱecognize the depth of those rivalries and assess their potential to reshape match outcomes.
my blokց :: 토토사이트 이용법
1win bet http://www.1win12.com.ng .
dark market 2025 dark market list
пин ап: https://pinupkz.life/
пин ап казино официальный сайт – пин ап вход
игровые автоматы вулкан платинум
пин ап зеркало: https://pinupkz.life/
Virtual gambling platforms have changed the casino gaming world, providing an exceptional degree of accessibility and selection that physical venues struggle to rival. Recently, countless gamblers around the world have turned to the excitement of digital casino play as a result of its availability, thrilling aspects, and widening collections of titles.
If you’re just starting with the world of online gaming or hope to learn about reputable operators, why not join our growing online hub? It’s a destination where enthusiasts share insights, enabling you to maximize your online casino experience. Explore the community and learn more now: https://www.dinoautoricambi.it/decorative6/
One of the biggest attractions of internet-based platforms is the sheer variety of titles ready to play. Whether you prefer interacting with traditional slot machines, trying out engaging video-based games, or mastering skills in strategy-based games like Texas Hold’em, virtual venues feature infinite opportunities. Several sites even offer live casino options, allowing you to communicate with human game hosts and gaming peers, all while immersing yourself in the realistic vibes of a brick-and-mortar establishment from the comfort of your home.
Adding to the extensive catalog, virtual gaming providers are known for ease of access.
пин ап – пин ап казино