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
Guide To Online Shopping Uk Discount: The Intermediate Guide On Online Shopping Uk Discount online Shopping uk Discount
10 Sites To Help You Become An Expert In Upvc Repairs Near Me repairing
What’s The Current Job Market For Which Is The Best Online Supermarket Professionals?
which Is the best Online supermarket
Всем привет! Подскажите, где найти разные блоги о недвижимости? Пока нашел https://1eve1.ru
5 Clarifications On Washer 10kg http://www.023456789.xyz
What’s The Current Job Market For Cheap Single
Stroller Professionals Like? Cheap single stroller
Five Killer Quora Answers To Online Home Shop Uk Discount Code online home shop Uk discount code
USP human growth hormone (somatropin).
Feel free to visit my page: Bookmarks
The 10 Most Terrifying Things About 18 Wheeler Accident Lawyers 18 wheeler accident lawyers
The 10 Most Scariest Things About List Of Online Shopping Sites In Uk list of online shopping sites in uk
Pills information. What side effects can this medication cause?
can i buy cheap estradiol price
Some news about meds. Get now.
5 Laws Everyone Working In Milton Keynes Windows And Doors Should Be
Aware Of Door Repair Milton Keynes
Railroad Injuries Lawyers Tools To Make Your Daily Life Railroad Injuries Lawyers
Technique Every Person Needs To Know Railroad Injuries Lawyers
How To Create Successful Replacement Upvc
Window Handles Tutorials On Home upvc window Repair near me
Learning a language does not need to be pricey.
My site: Bookmarks
9 Things Your Parents Teach You About Examples Of Online Shopping
examples Of online shopping
“‘ การ ปรับปรุง ของ Evolution Gaming ‘”
การ ปรับตัว และ ทันเหตุการณ์ เป็นเรื่องปกติในโลกของ เทคโนโลยีสารสนเทศ และธุรกิจ
ซึ่ง ‘Evolution Gaming’ เป็นหนึ่งในบริษัทที่สะท้อนแนวโน้มนี้อย่างชัดเจน
Evolution Gaming เป็นบริษัทชั้นนำในอุตสาหกรรม เกมโชคลาภ
ออนไลน์ โดย ก่อตั้งขึ้น ในปี
2006 และมีการ ขยายอิทธิพล อย่างต่อเนื่อง จนกลายเป็นหนึ่งในผู้นำด้านการให้บริการ เกมเสี่ยงโชค สดแบบออนไลน์ที่ใหญ่ที่สุดในโลก
ความ ความก้าวไกล ของ
Evolution Gaming มาจากการ ปรวนแปร
และ ทันเหตุการณ์นวัตกรรมอย่างต่อเนื่อง บริษัทมีการ ดำเนินการนำเทคโนโลยีล่าสุดมาใช้ในการออกแบบ เกมและการ ออกอากาศสด ผ่านแพลตฟอร์มออนไลน์
ทำให้ผู้เล่นสามารถ ได้สัมผัส ประสบการณ์ การเดิมพันแบบ ออนไลน์แบบไลฟ์ ได้อย่างสมจริง
นอกจากนี้ Evolution Gaming ยังมีการ ขัดเกลาบุคลากรภายในองค์กรอย่างต่อเนื่อง โดยการ ปรับปรุง ทักษะของ บุคลิกภาพ เพื่อให้สามารถ
รับมือ ความต้องการของ ผู้รับบริการ ได้อย่างมี ความเหมาะสม
ซึ่งเป็นปัจจัยสำคัญที่ทำให้
Evolution Gaming สามารถแข่งขัน และ ก้าวหน้า อย่างต่อเนื่องในตลาดที่มีการแข่งขันสูง
การ ปรวนแปร ของ Evolution Gaming
ไม่เพียงแต่สะท้อนถึงความ ความทันสมัย ขององค์กรเท่านั้น แต่ยังเป็นตัวอย่างที่ดีของการ เปลี่ยนแปลงและพัฒนา นวัตกรรมในโลกธุรกิจ
ซึ่งเป็นปัจจัยสำคัญที่จะนำไปสู่ ความทันสมัย และ ความต่อเนื่อง ในอนาคต
my web page :: เดิมพันคาสิโนออนไลน์
The majority of asbestos victims and their families begin the process
by hiring an experienced lawyer. A qualified
lawyer will help them prepare the lawsuit in order to claim compensation from the defendants
who made Asbestos Law-containing products.
where to get deltasone pill
Allow me reveal you in my testimonial of NewULife.
Feel free to visit my web blog: Ai Portrait Generator Free Reddit
Drug information sheet. What side effects?
get cheap divalproex tablets
All about medication. Get here.
You actually make it seem so easy with your presentation but I find this matter to be really
something that I think I would never understand. It seems
too complex and extremely broad for me. I’m looking forward
for your next post, I’ll try to get the hang of it!
10 Tell-Tale Signals You Should Know To Find A New Best CSGO Opening Site counter-Strike Cases
Wһen I initially commented I clicked the “Notify me when new comments are added”
checkboх and now each time a comment is added I get three
e-maiⅼs ѡith the same comment. Is there any way you can rеmove people from
that service? Bless you!
Feeⅼ free to surf to my site … browse this site
jasminer
Meds information leaflet. What side effects can this medication cause?
zithromax chemical name
Best about medicines. Read information here.
Medicine information for patients. Drug Class.
how to get cheap colchicine pill
Some news about pills. Read here.
This design is incredible! You most certainly know how to keep a reader entertained.
Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Fantastic job.
I really enjoyed what you had to say, and more than that,
how you presented it. Too cool! https://greatbookmarking.com/story17479050/pied-confort
I’m amazed, I must say. Seldom do I encounter a blog that’s equally educative and entertaining, and let me
tell you, you’ve hit the nail on the head.
The issue is something that too few folks are speaking intelligently about.
Now i’m very happy I came across this in my hunt for
something concerning this.
10 Volkswagen Keys Meetups You Should Attend Volkswagen Passat Key fob