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
https://amoxstar.com/# can you buy amoxicillin over the counter in canada
That is a great tip especially to those new to the
blogosphere. Brief but very precise info… Thank you for
sharing this one. A must read post!
Have a look at my webpage: ทางเข้า 1xbet
prednisone 20mg by mail order: prednisone 50 mg for sale – fast shipping prednisone
Excellente initiative ! Ce blog aide vraiment ceux qui cherchent des informations sur les fichet bordeaux
Сколько стоит диплом высшего и среднего образования и как его получить?
Keep An Eye On This: How Windows Aylesbury Is Taking Over And What To Do
About It double glazing seal repairs
where can i buy generic aurogra without a prescription where to buy aurogra prices cost of aurogra without prescription
where can i buy cheap aurogra price can you get generic aurogra without a prescription how can i get generic aurogra no prescription
how to buy cheap aurogra for sale
can i get aurogra without insurance can i order generic aurogra no prescription how to get cheap aurogra pills
can i order generic aurogra pills where buy cheap aurogra no prescription can i buy cheap aurogra without rx
Have you ever considered clever technology in your kitchen area? Integrating it with your lowes kitchen cabinets cupboards might enhance both design and performance
where to get clomid: where buy clomid price – where to buy cheap clomid without rx
http://amoxstar.com/# buying amoxicillin in mexico
prednisone 20mg prices prednisone cream rx prednisone cream rx
Guide To Heavy Duty Mobility Scooters: The Intermediate Guide The Steps To Heavy Duty Mobility Scooters Heavy duty
mobility scooters (http://www.stihiya-shop.by)
Good post. I absolutely appreciate this site. Continue the good work!
Dance Club 광주유흥
A Glimpse Inside Nespresso Machine Sale’s
Secrets Of Nespresso Machine Sale nespresso machines
dark market url darknet market dark markets
The 10 Scariest Things About Adult Adhd Assessments adhd assessments (Jacob)
I recently completed a cooking area remodel, and it has changed my cooking experience! If you’re thinking of updating your room small kitchen remodel
The 10 Scariest Things About Coffee Bean Near Me Coffee Bean near Me
12 Companies That Are Leading The Way In Fold Ramp For Wheelchair wheelchair
ramp 4ft [Russ]
Why visitors still use to read news papers when in this technological world all is accessible on web?
Быстрая схема покупки диплома старого образца: что важно знать?
http://prednibest.com/# prednisone 5 mg cheapest
50 mg prednisone canada pharmacy: PredniBest – prescription prednisone cost
Can I simply say what a relief to discover somebody
who genuinely knows what they are discussing on the net.
You actually understand how to bring a problem to light and make it important.
More and more people must look at this and
understand this side of the story. I can’t believe you are not more popular since you most certainly have the gift.
dark market 2024 dark web search engine darknet market
The Most Effective Ford Ranger Replacement
Key Tips To Transform Your Life replacement ford kuga
key (Dallas)
After using a service from #longdistancemovers long distance mover
Marilena-Hotel.com yaitu laman legal dari Marilena Hotel, destinasi penginapan yang
total untuk pengalaman wisata yang nyaman dan tak terlupakan. Terletak di lokasi
strategis dengan panorama yang mengagumkan, hotel ini
menawarkan fasilitas modern, layanan ramah, dan suasana yang hangat bagi para
tamu. Laman ini menyediakan isu lengkap perihal pilihan kamar, paket spesial, dan atraksi lokal,
serta kemudahan dalam menjalankan reservasi online.
Dengan desain elegan dan fokus pada kenyamanan, Marilena-Hotel.com menjadi gerbang menuju liburan yang santai dan penuh kenikmatan.
ใครชื่นชอบไวน์เหมือนกันบ้าง
แวะมาแนะนำร้านขาย wineไวน์ให้หน่อยสิ กำลังมองหาไวน์นำเข้าคุณภาพดีอยู่
ถ้าคุณรู้จักร้านไวน์ดีๆ บอกต่อกันนะ ไวน์ดีๆ จะช่วยเพิ่มบรรยากาศให้ทุกมื้ออาหาร รอคำตอบจากทุกคนอยู่นะ
เว็บไซต์นี้มีข้อมูลที่น่าสนใจมาก
อยากให้เพิ่มเนื้อหาเกี่ยวกับไวน์มากกว่านี้ เว็บไซต์นี้เหมาะกับคนที่อยากเรียนรู้เรื่องไวน์มาก
หวังว่าทุกคนจะมีความสุขกับการดื่มไวน์ จะติดตามเว็บนี้ต่อไปเรื่อยๆ ค่ะ ขอบคุณมากค่ะ!