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
buy diflucan online south africa
What’s The Current Job Market For Mercedes Ignition Key Professionals Like?
Mercedes ignition Key
การพัฒนาและสร้างเกม Relax Gaming ล่าสุด
ยามนี้ นี้ใน วงจรเกม ออนไลน์
ที่กำลังเติบโต อย่างมาก บริษัทที่ RelaxGaming Casino กำลังจะพยายามเป็นที่
โดยพิสัย อย่างมากมาย ด้วย การพัฒนาและสร้าง เกมเป็น ที่สร้างความบันเทิง และอีก ประสบการณ์ ที่น่าตื่นตาตื่นใจ ให้แก่ นักเล่น ทั่ว
โลกของเรา บริษัทนี้
ไม่เพียงแต่เพียงแค่ มีความเกม หลากหลายแนวทาง และอีก น่าสนใจมากเท่า ด้วย แต่ยัง มุ่งมั่นในการ การพัฒนาเทคโนโลยี ที่ เพื่อให้ การเล่นเกม เป็นประสบการณ์ ประสบการณ์ที่ ที่สมบูรณ์ ด้วย ทีม ผู้พัฒนาเกม ที่มีความเชี่ยวชาญ และ การมุ่งมั่น
ในการสร้างเกมเป็น เกมที่ เอกลักษณ์เฉพาะ RelaxGaming กำลังจะก้าวไปข้างหน้า อย่างแน่นอนอย่างแน่นอน
ใน วงการเกมออนไลน์ แห่งนี้
ดังนั้น, อย่า พลาด
เกมล่าสุดของ RelaxGaming ที่กำลังจะ ได้รับรางวัล และคว้าใจคุณ อย่างแน่นอนแน่น!
Feel free to visit my site; เว็บคาสิโนออนไลน์ที่มีระบบรักษาความปลอดภัยระดับสูง และมีมาตรฐานการให้บริการที่ได้รับการยอมรับจากนักพนันทั่วโลก (https://artmight.com/user/profile/2933392)
It’s remarkable for me to have a web page, which is good designed for my experience.
thanks admin
See What Examples Of Online Products Tricks The Celebs Are Using
Examples Of Online Products
It’s A Jackpot Slots Success Story You’ll Never Imagine Play Slots
17 Signs To Know If You Work With Which Is Best For Online Grocery Shopping Furinno Hardwood Dining Table
You can definitely see your enthusiasm in the article
you write. The arena hopes for even more passionate writers
such as you who are not afraid to say how they believe.
All the time follow your heart.
10 Sites To Help Learn To Be An Expert In High
Roller Slots slot providers (https://m.jingdexian.com/home.php?mod=space&uid=2900789)
With thanks! Numerous advice!
See What Double Glazing Crawley Tricks The Celebs Are Using double glazing crawley (Danilo)
Unexpected Business Strategies That Aided Double Glazed
Replacement Glass Near Me To Succeed Double Glaze Doors
The Next Big Trend In The Panels For Upvc Doors Industry replace lock On upvc Door (http://125.141.133.9/)
The Unspoken Secrets Of Window Repair Near window repairs
Slot Apps 101 It’s The Complete Guide For Beginners Mobile Slots
15 Shocking Facts About How To Ship To Ireland From Uk That You Didn’t Know Natural Area Rugs
Hello, I do think your site could be having browser compatibility issues.
When I look at your web site in Safari, it looks fine however, if opening in I.E., it’s
got some overlapping issues. I simply wanted to provide you with
a quick heads up! Apart from that, wonderful blog!
Highly descriptive article, I loved that a lot. Will there
be a part 2?
Hello! This post couldn’t be written any better!
Reading this post reminds me of my previous room mate! He always kept
talking about this. I will forward this post to him. Pretty sure he will
have a good read. Thanks for sharing!
My spouse and I absolutely love your blog and find the
majority of your post’s to be exactly I’m looking for.
Would you offer guest writers to write content available for you?
I wouldn’t mind writing a post or elaborating on some of
the subjects you write related to here. Again, awesome web log!
Medicine information. Generic Name.
where to get rizatriptan no prescription
Everything what you want to know about meds. Read information now.
15 Unquestionable Reasons To Love Online Shopping Sites In United Kingdom Lr Liquid Rubber Bonding Agent
серия
Your Family Will Be Grateful For Having This Counter Strike
Play Case Falchion
This Is The Myths And Facts Behind Key Programer programming a key (Claribel)
1win казино: Топ игр с высокими выплатами http://azena.co.nz/bbs/board.php?bo_table=free&wr_id=388056
10 Quick Tips About Safe Mobility Scooters embargo.Energy
Great post. I used to be checking constantly this weblog and I am inspired!
Extremely useful info particularly the last phase 🙂 I deal with such information much.
I was seeking this particular information for a very long time.
Thank you and good luck.
I feel that is one of the such a lot significant information for me.
And i’m happy studying your article. But want to commentary on few normal things, The web
site taste is perfect, the articles is actually great :
D. Excellent job, cheers
Visit my blog post; the genius wave
A Reference To Window Replacement Cost From Beginning To
End window replacement cost uk