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
reputable mexican pharmacies online: mexican drugstore online – reputable mexican pharmacies online
https://storage.googleapis.com/accounting0016/research/accounting0016-(91).html
For mothers who swoon for all things sassy, the dramatic gold mother of the bride dress can be the picture-perfect decide in 2022.
mexican rx online: mexican border pharmacies shipping to usa – mexico pharmacies prescription drugs
mexican border pharmacies shipping to usa: mexican border pharmacies shipping to usa – pharmacies in mexico that ship to usa
mexico pharmacies prescription drugs: mexican drugstore online – mexican border pharmacies shipping to usa
The Greatest Sources Of Inspiration Of Citroen Berlingo Key Fob replacement citroen key fob (https://minecraftcommand.science/profile/sharonzipper17)
https://eu2.contabostorage.com/31daf39818d34828bb743ca15445c2b7:ya-tendoncare-23/pulling-tendons-and-health-care-for-athletes.html
That stated, having such a extensive variety of choices may really feel somewhat overwhelming.
The Most Pervasive Problems In Where To Buy Chest Freezer what is the best rated chest Freezer
reputable mexican pharmacies online: buying prescription drugs in mexico online – п»їbest mexican online pharmacies
https://bogin001.netlify.app/research/bogin001-(152)
With palm leaf décor and many vines, green was a primary theme throughout this charming and colourful South Carolina celebration.
It’s awesome to pay a visit this website and reading the views of all colleagues concerning this article, while I am also eager of getting
experience.
20 Quotes That Will Help You Understand Upvc Window Near Me
wickes Upvc Windows
Meds information sheet. Generic Name.
lisinopril for sale
Best information about drugs. Read information here.
Is Your Company Responsible For The Affordable Couches For Sale Budget?
12 Ways To Spend Your Money Couches for sale manchester
One Coffee Pod Makers Success Story You’ll Never Believe
http://www.822547.xyz
The No. 1 Question Everyone Working In Malpractice Lawsuit Should Be Able Answer Malpractice lawyer [http://www.sitiosecuador.com]
medicine in mexico pharmacies mexican pharmacy mexican online pharmacies prescription drugs
Greetings! Very helpful advice within this article!
It is the little changes which will make the
most significant changes. Thanks for sharing!
buying prescription drugs in mexico: buying prescription drugs in mexico – reputable mexican pharmacies online
purple pharmacy mexico price list mexican border pharmacies shipping to usa best online pharmacies in mexico
best online pharmacies in mexico: mexican pharmaceuticals online – buying prescription drugs in mexico online
20 Things That Only The Most Devoted Erb’s Palsy Case Fans Know Erb’s Palsy Lawyers
purple pharmacy mexico price list purple pharmacy mexico price list purple pharmacy mexico price list
I visited several blogs but the audio quality for audio songs current at this web page is in fact wonderful.
ซุปเปอร์สล็อต168 ที่สุดของเว็บเกมสล็อตที่คุ้มค่าสำหรับคุณ
Why You Should Not Think About Improving Your Upvc Windows Repair
repair Upvc Windows
Five Killer Quora Answers To Replacement Double Glazing Units Near Me replacement double glazing Units near me
medication from mexico pharmacy: pharmacies in mexico that ship to usa – best online pharmacies in mexico
15 Up-And-Coming Psychiatry Facilities Near Me Bloggers You Need To
Check Out best adhd psychiatrist near me
https://ya-catering33.br-gru-1.linodeobjects.com/marketing-plan-for-catering-services.html
But an important piece of attire you’ll choose main up to your kid’s wedding?