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
Search Engine Optimization Strategies – Keyword Density 백링크 검사 (strangepeople.com)
I’m very pleased to find this site. I need to to thank you
for ones time for this fantastic read!! I definitely
liked every little bit of it and I have you saved to
fav to look at new information in your blog.
Medication information. Drug Class.
get ceftin pill
Actual news about medicine. Read here.
I needed to thank you for this very good read!!
I certainly loved every little bit of it. I have got you book-marked to check out new things you post…
Wow, this paragraph is pleasant, my younger sister is analyzing these kinds of things, therefore I am going
to inform her.
Lorem Ipsum has been the industry’s standard dummy text https://allafricanpokerguide.co.za/lxndyt of type and scrambled it to make a type specimen book.
You’ll Never Guess This Double Glaze Repair Near Me’s Secrets Double glaze repair near me
9 . What Your Parents Taught You About Window Replacement Near Me
window replacement near me (https://pipewiki.org/app/index.php/user:isobelcarron1)
Drugs information for patients. Effects of Drug Abuse.
get cheap requip tablets
Actual information about drug. Get information now.
10 Misconceptions Your Boss Has About Program A Key 5611432
Why Medical Malpractice Compensation Isn’t A Topic That People Are Interested In Medical Malpractice
Compensation medical Malpractice Attorney
Excellent blog right here! Also your web site quite a bit up very fast!
What web host are you the use of? Can I am getting
your associate hyperlink to your host? I want my site loaded up as fast as yours lol
If you want to get much from this piece of writing then you have to
apply these strategies to your won blog.
The Complete Guide To Window Repairs Upvc Window Repairs
Pills information leaflet. Short-Term Effects.
where to get anastrozole tablets
Everything what you want to know about medicines. Get here.
Va Asbestos Claims Explained In Fewer Than 140 Characters 9363280
casino
With havin so much written content do you ever run into any
problems of plagorism or copyright violation? My website has a lot of completely unique content I’ve either
written myself or outsourced but it seems a lot of it is popping it up all
over the web without my permission. Do you know any methods
to help reduce content from being stolen? I’d genuinely
appreciate it.
Feel free to visit my web blog :: sex partners near
me (Edythe)
13 Things You Should Know About Bunk Beds For Children That You Might Not Know Edda Fay
Recognizing The Advantages And Disadvantages Of A Debt Consolation Loan 리드코프 무직자 대출
cakhiaq.tv lua dao nguoi choi ca do va dam me bong da va the thao
การ ทำ “หวยฮานอย” เป็นอีก โอกาส
หนึ่งที่ได้รับ ความสนใจ จาก ผู้คนในประเทศไทย ในการ
ลุ้นรางวัล เมื่อ เหมือนกับ การ ทำ
หวยรัฐบาลหรือ”หวยลาว”
ความ น่าตื่นเต้น ของ”หวยฮานอย”คือ การ จัดการออกรางวัล ทุกวัน ส่งผลให้ผู้ เสี่ยง สามารถ รับรางวัล ได้บ่อยครั้ง และ
สามารถ สร้าง รายได้ใหม่ จากการ ซื้อ หวย
อย่างไรก็ตาม การ ทำ “หวยฮานอย” ก็ไม่ ข้อเสีย เนื่องจากผู้ ซื้อ บางรายอาจ ใช้จ่าย มากเกินไปหรือ ป่วยเป็น การพนัน ซึ่งอาจ ทำให้เกิดผลลบ ต่อ สุขภาพ นอกจากนี้ ยังมี ความเป็นไปได้ เรื่อง การกระทำที่ผิดกฎหมาย จากผู้ที่ ต้องการผลกำไร โดยมิชอบ
เพื่อให้การ ซื้อ “หวยฮานอย” เป็นเพียงการ เล่นเพื่อความมุ่งหวัง เพื่อ ความเพลิดเพลิน
และ ไม่ส่งผลกระทบ จึงควรมีการ ปกป้อง และกำกับดูแล อย่างใกล้ชิด เช่น การกำหนด วงเงิน ในการ เสี่ยง ที่
สมควร รวมถึงการ ตรวจตรา ผู้กระทำผิด ทั้งนี้เพื่อให้การ พนัน “หวยฮานอย” เป็นส่วนหนึ่งของการใช้เวลาว่าง อย่าง มีวินัย และ ไม่ทำร้าย ความเป็นอยู่ ของผู้ ลุ้น
my blog post คาสิโนออนไลน์มือถือ
I am sure this piece of writing has touched all the internet visitors, its really really pleasant paragraph on building up new blog.
It is appropriate time to make some plans for
the future and it’s time to be happy. I’ve learn this submit and if I
may just I want to recommend you few attention-grabbing things or
advice. Perhaps you could write subsequent articles relating to this article.
I desire to learn even more issues about it!
Medicament information for patients. Cautions.
how can i get divalproex no prescription
Everything what you want to know about medicine. Read now.
Quality articles or reviews is the key to attract the visitors to
visit the web page, that’s what this site is providing.
Drug information leaflet. Drug Class.
como comprar pastillas de flibanserina
Everything news about medicament. Read now.
porn cannibalism
Our team is as passionate about cricket as you are, and we’re here to make your betting experience unforgettable https://cricetc1xbeticricetec2.ru/.