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
Just wanted to share how much I love my newly built home from Keechi Creek; it’s everything we hoped for houston texas home builders
cost of amoxicillin 875 mg: amoxicillin 30 capsules price – buy amoxicillin 250mg
Junk removal can be stressful junk removal san francisco
Покупка диплома о среднем полном образовании: как избежать мошенничества?
http://prednibest.com/# prednisone coupon
Under tiden som dessa gratis snurr pågår multipliceras samtliga dina vinster med 3, om spelaren kommer att ta ut sina 20 pund.
where buy clomid without a prescription: clomidonpharm – get clomid online
5 Laws That Will Help The Adhd Assessment For Adults
Industry psychiatry-uk adhd assessment (images.google.td)
5 Qualities People Are Looking For In Every Coffee Bean Machine beans to cup coffee machines (Claude)
Как не попасть впросак при покупке диплома колледжа или ПТУ в России
Тhank you for thе good writeup. It in fact was a amuѕement accounmt it.
Look advanced to far added agreeable from
you! By the way, how could we communicate?
Feel free to surf to my weƄ page … dede4D
Very nice article. I definitely appreciate this website.
Continue the good work!
Hello colleagues, how is everything, and what you would like to say concerning this article, in my view its
actually awesome designed for me.
darkmarkets darkmarket link dark web markets
cipro for sale cipro for sale buy cipro online canada
We absolutely love your blog and find many of your post’s to be precisely what I’m looking
for. Does one offer guest writers to write content in your case?
I wouldn’t mind publishing a post or elaborating on most of the subjects you write with
regards to here. Again, awesome weblog!
http://amoxstar.com/# amoxicillin 775 mg
can i order cheap clomid without rx: clomid on pharm – where can i buy clomid pills
Why We Why We Natural ADHD Medication (And You
Should Also!) common adhd medications
Your exploration of biometric locks became eye-starting! They seem to be the long run of protection locksmith
Thanks for finally talking about > JS 依照元素出現數量排序 – 馬老師
雲端研究室 < Loved it!
ใครชื่นชอบไวน์เหมือนกันบ้าง ช่วยแชร์ประสบการณ์ซื้อไวน์หน่อยค่ะ อยากลองไวน์ที่มีรสชาติเป็นเอกลักษณ์
ใครมีร้านโปรดอย่าลืมแชร์กัน
การรู้จักไวน์ที่เหมาะกับตัวเองสำคัญมาก รอคำตอบจากทุกคนอยู่นะ
บทความที่แชร์ในเว็บนี้มีประโยชน์มากเลย หวังว่าจะมีบทความใหม่ๆ เพิ่มเติมเกี่ยวกับไวน์ เว็บไซต์นี้เหมาะกับคนที่อยากเรียนรู้เรื่องไวน์มาก
สุดท้ายนี้ขอให้ทุกคนเจอไวน์ที่ชอบนะคะ
จะติดตามเว็บนี้ต่อไปเรื่อยๆ ค่ะ ขอบคุณมากค่ะ!
My blog :: จำหน่ายไวน์
Love sharing experiences regarding renovations with fellow homeowners! Connect via discussions found via avalon roofing services
http://amoxstar.com/# canadian pharmacy amoxicillin
Легальная покупка школьного аттестата с упрощенной программой обучения
Private Party Op (Ise.Ait.Ac.Th)
Are You Getting The Most Of Your Commercial Truck Accident Attorney?
Truck Wreck Lawyers
You’ll Never Guess This Home Espresso Machine’s Tricks Home Espresso Machine
Remarkable! Its genuinely remarkable article, I have got much clear idea about from this article.
dark market url dark web market blackweb official website