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
purple pharmacy mexico price list: mexican online pharmacies prescription drugs – mexico drug stores pharmacies
A Journey Back In Time: What People Discussed About Audi
Spare Key 20 Years Ago cost of audi key replacement (mullins-Busk.Federatedjournals.com)
Mens Toys Adult: The History Of Mens Toys Adult In 10 Milestones adult sex
toy for men (https://www.similarityapp.com)
shipping vehicle across country shipping vehicle across country .
mexican drugstore online: mexican online pharmacies prescription drugs – mexico drug stores pharmacies
What Is Upvc Windows And Doors Near Me And Why Are We Talking About It?
upvc window lock Mechanism
15 Things You’ve Never Known About Saab 9-3 Replacement Key Saab 9-3 Key Programming
Bunk Beds L Shaped Tools To Streamline Your Everyday Lifethe Only Bunk Beds L Shaped
Technique Every Person Needs To Be Able To bunk beds L shape
buying from online mexican pharmacy: mexican border pharmacies shipping to usa – buying prescription drugs in mexico
The 3 Greatest Moments In Windows Repair History window repair
I am in fact thankful to the owner of this website who has
shared this enormous piece of writing at at this time.
mexico drug stores pharmacies: medicine in mexico pharmacies – best online pharmacies in mexico
You’ll Never Guess This Slot Demo Rush Sugar’s Benefits Slot Demo Rush Sugar
mexico drug stores pharmacies mexican border pharmacies shipping to usa mexican mail order pharmacies
purple pharmacy mexico price list: mexican online pharmacies prescription drugs – pharmacies in mexico that ship to usa
best online pharmacies in mexico: п»їbest mexican online pharmacies – mexico drug stores pharmacies
You ougһt to take part in a contest for one of thе grеatest
websites online. І will recommend tһіs site!
Here is my blog post :: govas.ac.id
buying prescription drugs in mexico: medication from mexico pharmacy – п»їbest mexican online pharmacies
reputable mexican pharmacies online: mexico drug stores pharmacies – best online pharmacies in mexico
is significant enough to overwhelm our immediate coping skills.高級 ラブドールThese can be one-time events or prolonged ones such as accidents,
15 Undeniable Reasons To Love Employers Liability Act Fela federal employers’ liability
I’ve learn several excellent stuff here. Certainly price bookmarking
for revisiting. I wonder how so much attempt you put to make one of these excellent informative site.
10 Places That You Can Find Mesothelioma Asbestosis cassylawn.Top
9 Lessons Your Parents Teach You About Bifold Doctor bifold Doctor
(menwiki.men)
10 Apps To Help You Manage Your Hisense Fridge Freezer With Water
Dispenser fridge with filtered water dispenser; https://fridge74111.ivasdesign.com/50786268/how-to-find-the-perfect-samsung-fridge-freezer-with-water-dispenser-on-the-internet,
medicine in mexico pharmacies: mexican border pharmacies shipping to usa – mexican border pharmacies shipping to usa
It’s great that you are getting thoughts from this piece of writing as
well as from our dialogue made here.
Guide To Best All Terrain Pram: The Intermediate Guide For Best All Terrain Pram Best All Terrain Pram
buying prescription drugs in mexico: mexico drug stores pharmacies – pharmacies in mexico that ship to usa
What Is Window Glass Repair Near Me And How To Utilize What Is Window
Glass Repair Near Me And How To Use window glass Repair services near me