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
Where Will Upvc Replacement Window Handles Be One Year From In The
Near Future? upvcwindows
https://ya-4545-11.se-sto-1.linodeobjects.com/company-registration-and-corporate-governance.html
Sparkling night robe options an allover beaded design with a modest v-neckline and quick sleeves.
The Most Convincing Proof That You Need Window Replacement Replacement Window
9 . What Your Parents Taught You About Upvc Windows Near Me upvc windows near me
mexico pharmacies prescription drugs: mexican pharmaceuticals online – reputable mexican pharmacies online
Great web site you’ve got here.. It’s hard to find good quality writing like yours these
days. I honestly appreciate individuals like you! Take care!!
mexico pharmacies prescription drugs medicine in mexico pharmacies mexican pharmacy
ラブドールYour clear and engaging writing style is truly inspiring,as I am confident they will continue to offer valuable advice and practical solutions.
Good day! This is my 1st comment here so I
just wanted to give a quick shout out and tell you I genuinely enjoy reading through your posts.
Can you suggest any other blogs/websites/forums that cover the same subjects?
Thanks a ton!
https://filedn.eu/lXvDNJGJo3S0aUrNKUTnNkb/ya-chinavisa-8/how-to-use-the-taiwan-compatriot-certificate-in-mainland-china.html
You actually want to take into consideration what’s finest for the season, and the weather you’ll be sitting in.
You’ll Never Guess This Upvc Window Repair’s Tricks upvc window repair
buying prescription drugs in mexico: buying from online mexican pharmacy – buying prescription drugs in mexico online
https://storage.googleapis.com/digi7/research/digi7-(488).html
It is customary to avoid sporting white in your children’s marriage ceremony day.
mexican border pharmacies shipping to usa: mexico pharmacies prescription drugs – mexico drug stores pharmacies
Do you mind if I quote a few of your posts as long as I provide credit and sources back to your
site? My website is in the exact same niche as yours and my visitors would genuinely benefit from some of the information you
present here. Please let me know if this alright with you.
Appreciate it!
Guide To Double Glazing Repairs Near Me: The Intermediate Guide For Double Glazing Repairs Near Me double glazing Repairs near me
mexico drug stores pharmacies: п»їbest mexican online pharmacies – mexico pharmacies prescription drugs
7 Simple Secrets To Totally Moving Your Peugeot Car Key
Replacement peugeot partner van key
20 Things Only The Most Devoted Mattress Toppers Double Fans
Understand cooling mattress topper (https://philipsen-gram-2.blogbright.net/where-can-you-get-the-most-reliable-which-mattress-toppers-are-best-information)
medicine in mexico pharmacies: mexico pharmacies prescription drugs – mexican rx online
reputable mexican pharmacies online: buying prescription drugs in mexico – buying prescription drugs in mexico
Upvc Door Repairs Near Me Tools To Make
Your Everyday Lifethe Only Upvc Door Repairs Near Me Technique Every Person Needs To Know upvc door
repairs near me (mariskamast.net)
mexican border pharmacies shipping to usa: mexican online pharmacies prescription drugs – pharmacies in mexico that ship to usa
purple pharmacy mexico price list: mexican pharmaceuticals online – buying prescription drugs in mexico
10 Websites To Help You To Become An Expert In Slot Demo demo slot rujak
bonanza (Christal)
mexican drugstore online: medication from mexico pharmacy – medication from mexico pharmacy
The 10 Most Terrifying Things About Can Mobility Scooters Go On The Road can mobility Scooters go on the Road
I all the time used to read post in news papers but now as I
am a user of web so from now I am using net for
articles, thanks to web.
https://filedn.eu/lXvDNJGJo3S0aUrNKUTnNkb/accounting5/research/accounting5-(90).html
This gorgeous robe is made from double-stretch Mikado for a streamlined, comfy match.
5 Arguments Akun Demo Slot Pragmatic Is A Good Thing oscarreys.Top (oscarreys.Top)