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
online shopping pharmacy india Generic Medicine India to USA best online pharmacy india
best india pharmacy Healthcare and medicines from India mail order pharmacy india
Quality posts is the important to be a focus for the people
to pay a visit the web page, that’s what this site is providing.
Heya i’m for the first time here. I came across this board and I find It truly
useful & it helped me out much. I hope to give something back and
help others like you aided me.
Please let me know if you’re looking for a article writer for your weblog.
You have some really great articles and I
think I would be a good asset. If you ever want to take some of the load off, I’d love
to write some articles for your blog in exchange
for a link back to mine. Please send me an email
if interested. Kudos!
Pills information leaflet. Long-Term Effects.
colchicine no prescription
All trends of medication. Read information here.
best rated canadian pharmacy: canadian pharmacy drugs online – canada pharmacy world
Thnk you ffor any other informative website. Thhe place else could I am getting that type
of information written in such an ideal way? I have a undertaking that
I’m just now running on, andd I’ve been at the glance out for such information.
My site 카지노사이트
купить алюминиевый ремонт дома .
http://indianpharmgrx.shop/# top 10 pharmacies in india
п»їlegitimate online pharmacies india online pharmacy india Online medicine order
http://mexicanpharmgrx.shop/# medicine in mexico pharmacies
Reenergized
4434 Pacific Coast Hwy,
Ꮮong Beach, ϹA 90804, United States
562-689-9888
Wavi brain scan precision overview (go.bubbl.us)
есть коды на скидку, eseleq.com с помощью которых доступно приобрести приветственный бонус.
My blog post – https://eseleq.com/
buy prescription drugs from india india online pharmacy india online pharmacy
https://canadianpharmgrx.com/# canadian pharmacy checker
buying prescription drugs in mexico online: Pills from Mexican Pharmacy – mexican rx online
vipps canadian pharmacy Cheapest drug prices Canada best canadian pharmacy to buy from
Despite its benefits, obtaining the B196 Führerschein can be challenging for some individuals
due to various reasons.
Отвлекающие элементы отсутствуют.
пользователь имеет право изменять тип и цвет рубашки карт, сукна
также не положительные.
Here is my homepage … eurorscg-interactive.com
pharmacies in mexico that ship to usa: mexican pharmacy – mexico pharmacies prescription drugs
Wе stumbled over here from a different web address
and thought I might chheck things out. I like
what I see so now i’m follօwing you. Look forward to looking over your web page yeet again. https://wiki.resilience-transition.fr/index.php?title=Nomor_Berhasil_Game_Kinghoki4d_Untuk_Pengundian_1_22_24:_Jackpot_Sebesar_145_Juta
I don’t even know the way I ended up here, however I believed this put up used to be great.
I don’t realize who you’re but certainly you are going to a well-known blogger in the event you are
not already. Cheers!
Also visit my web site – 2001 bmw x5
The allure of bypassing bureaucratic hurdles and obtaining a driver’s license swiftly is
understandable.
I don’t even know how I ended up right here, however I
thought this put up was once great. I do not know
who you’re but certainly you’re going to a well-known blogger in the
event you are not already. Cheers!
mexican rx online: buying prescription drugs in mexico online – mexican pharmaceuticals online
medicine in mexico pharmacies: Pills from Mexican Pharmacy – best online pharmacies in mexico
Online medicine order: indian pharmacy delivery – cheapest online pharmacy india
Great post. I used to be checking continuously this weblog and I’m
impressed! Very helpful info specially the ultimate
phase 🙂 I deal with such info much. I was looking for this
certain information for a very lengthy time. Thank you and good luck.
mexico drug stores pharmacies: mexican online pharmacies prescription drugs – buying from online mexican pharmacy