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
mexican rx online: cmq mexican pharmacy online – mexico drug stores pharmacies
I have been surfing online more than 4 hours today, yet I never found any interesting article like yours.
It is pretty worth enough for me. In my opinion, if all web owners and
bloggers made good content as you did, the net will be a
lot more useful than ever before.
Here is my web page asbestos removal ottawa
п»їbest mexican online pharmacies
http://cmqpharma.com/# mexican rx online
mexican border pharmacies shipping to usa
where to get generic albuterol without insurance
mexico drug stores pharmacies: cmq pharma mexican pharmacy – mexican rx online
Hello outstanding website! Does running a blog such as this require a
lot of work? I’ve virtually no understanding of coding however I had been hoping to start my own blog in the
near future. Anyway, if you have any recommendations
or techniques for new blog owners please share. I understand this is off
subject however I just needed to ask. Appreciate it!
Have a look at my site :: copier service austin
mexican pharmacy: cmq pharma – best online pharmacies in mexico
Добрый день!
Заказать диплом ВУЗа.
Наш сервис предлагает приобрести диплом в высоком качестве, неотличимый от оригинала без участия специалистов высокой квалификации со специальным оборудованием.
Где заказать диплом по актуальной специальности?
http://mdr7.ru/viewtopic.php?f=6&t=8707
Хорошей учебы!
does colchicine increase bleeding risk
The People Closest To Mesothelioma Asbestos
Uncover Big Secrets Jayson
Double Glazing Window Locks Repairs: It’s
Not As Difficult As You Think jerealas
purple pharmacy mexico price list: cmqpharma.com – purple pharmacy mexico price list
medication from mexico pharmacy: cmq pharma – п»їbest mexican online pharmacies
can i purchase generic duphalac prices
purple pharmacy mexico price list: buying from online mexican pharmacy – purple pharmacy mexico price list
medication from mexico pharmacy: cmq mexican pharmacy online – reputable mexican pharmacies online
Pretty portion of content. I just stumbled upon your web site and in accession capital to claim that I acquire in fact loved account your weblog
posts. Any way I will be subscribing for your augment and even I fulfillment you get admission to constantly quickly.
10 Of The Top Mobile Apps To Double Glazing Repair Kit jerealas
п»їbest mexican online pharmacies: mexican online pharmacy – reputable mexican pharmacies online
medicine in mexico pharmacies
https://cmqpharma.com/# mexico pharmacies prescription drugs
mexico drug stores pharmacies
Приветствую. Может кто знает, где найти полезные блоги о недвижимости? Сейчас читаю https://teplohod-denisdavidov.ru
buying from online mexican pharmacy: mexico pharmacy – mexico pharmacies prescription drugs
ремонт стиральных машин ремонт стиральных машин .
buying from online mexican pharmacy
http://cmqpharma.com/# buying from online mexican pharmacy
п»їbest mexican online pharmacies
If some one wants expert view regarding running a blog then i advise him/her to go to see this blog,
Keep up the fastidious work.
mexico pharmacies prescription drugs
http://cmqpharma.com/# medicine in mexico pharmacies
mexican online pharmacies prescription drugs
mexico pharmacies prescription drugs
http://cmqpharma.com/# mexican pharmaceuticals online
mexican rx online
where to get cheap tinidazole without a prescription
where to get cheap lyrica no prescription
can i purchase cheap amaryl online