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
can i order generic clomid price where buy generic clomid price cost generic clomid for sale
http://clomidonpharm.com/# can i purchase generic clomid
Modifications On Casino Keno 에볼루션 바카라 보너스
dark market list deep web drug url blackweb official website
Thanks for sharing your thoughts. I really appreciate your efforts and
I am waiting for your further write ups thank you once again.
With so many choices out there, it’s great to have an agency like Chicago business health insurance guiding us through it all
where can i buy cipro online: CiPharmDelivery – cipro online no prescription in the usa
789win là nhà cái trực tuyến hàng đầu Châu Á
với nhiều loại hình cá cược như thể thao,
casino, slot game,… mang đến trải nghiệm chơi mượt mà và an toàn.
buying prednisone on line: online order prednisone 10mg – where can you buy prednisone
It’s very simple to find out any topic on web as compared to books, as I
found this article at this web page.
Here is my homepage … skilled nursing and memory care
antibiotic amoxicillin: buy amoxicillin 500mg – buy amoxil
Merci pour ces informations claires sur ce que fait un serrurier bordeaux centre
I just like the valuable information you provide in your articles.
I will bookmark your weblog and take a look at once more right here regularly.
I’m somewhat certain I’ll learn many new stuff right here!
Good luck for the following!
Как официально купить аттестат 11 класса с упрощенным обучением в Москве
The 10 Most Terrifying Things About Trucking Accidents Attorneys trucking accidents attorneys
Предлагаем услуги профессиональных инженеров офицальной мастерской.
Еслли вы искали ремонт стиральных машин smeg адреса, можете посмотреть на сайте: ремонт стиральных машин smeg сервис
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
https://gazetablic.com/new/?code_promo-1win-bonus_de_500.html
buy amoxicillin online uk how much is amoxicillin can i purchase amoxicillin online
can i buy clomid without prescription: where to buy generic clomid tablets – can i get generic clomid prices
deep web drug markets blackweb official website dark web market
Home inspections are essential anywhere—but especially on islands like Puerto Rico! Use # Energy efficiency inspections # for reliable service
Terrific post however I was wondering if you could write a litte more on this subject?
I’d be very thankful if you could elaborate a little bit
further. Cheers!
Ahaa, its nice dialogue concerning this article here at this web site, I
have read all that, so at this time me also commenting here.
where to buy cheap clomid without rx: order generic clomid – where to buy cheap clomid pill
Интересные статьи о займах – http://www.matrixplus.ru/statraz28045.htm
Wonderful, what a website it is! This weblog provides useful
information to us, keep it up.
вывод из запоя в спб вывод из запоя в спб .
can i purchase generic clomid tablets: clomid on pharm – buy clomid tablets
Hey there! I understand this is kind of off-topic but I needed to ask.
Does running a well-established blog such as yours require a lot of work?
I’m brand new to blogging but I do write in my diary everyday.
I’d like to start a blog so I can share my own experience and feelings
online. Please let me know if you have any ideas or tips for
new aspiring bloggers. Thankyou!
You made some nice points there. I did a search on the subject matter and found mainly persons will
have the same opinion with your blog. https://F2b.s3-Web.eu.cloud-Object-storage.appdomain.cloud/