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://stromectol.fun/# buy stromectol uk
lasix dosage: lasix medication – lasix furosemide 40 mg
Looking For Inspiration? Try Looking Up GSA SEO VPS Gsa software seo
http://buyprednisone.store/# prednisone 1 mg for sale
This is nicely expressed. .
amoxicillin 500mg capsules price: generic amoxicillin – amoxicillin 500mg price canada
amoxicillin 500 capsule: amoxicillin 500mg capsules price – where can i buy amoxicillin over the counter
The 3 Most Significant Disasters In Double Glazing Window
Replacement The Double Glazing Window Replacement’s 3
Biggest Disasters In History Double Glazing Window Replacement
furosemide 40mg Over The Counter Lasix lasix dosage
This is my first time visit at here and i am really pleassant to read all at one place.
stromectol ireland stromectol pill for humans stromectol 3 mg price
%%
My web blog; Affordable Seo company near Me
A motivating discussion іs defіnitely worth cⲟmment.
I do beⅼieve that you ought to publish mߋre on tһis subject, іt
mɑy not be a taboo matter but generally folks don’t discuss such subjects.
To thе next! Kіnd reɡards!!
My blog post; lotto bet; Vito,
where can i get amoxicillin: amoxicillin 500 mg cost – amoxicillin canada price
I’m extremely impressed with your writing skills as well as with the layout on yourblog. Is this a paid theme or did you customize it yourself?Either way keep up the nice quality writing, it’srare to see a great blog like this one nowadays.
https://buyprednisone.store/# where can i buy prednisone without a prescription
Actually no matter if someone doesn’t be aware of afterward
its up to other people that they will help, so here it occurs.
http://amoxil.cheap/# cost of amoxicillin 875 mg
Купить кондиционер в Рязани по лучшим ценам. Сплит-системы с гарантией до 5 лет от компании https://vk.com/kupit_kondicioner_ryazan
furosemide 40mg: lasix 100 mg tablet – buy lasix online
Предоставляем услуги комплексного бухгалтерского обслуживания юридических лиц. Ведение бухгалтерского учета по выгодным ценам — для вашего бизнеса услуги по составлению бухгалтерской отчетности
Link exchange is nothing else but it is only placing the other person’s web site link on your page
at proper place and other person will also do same in support of
you.
https://lisinopril.top/# lisinopril 40 coupon
10 Quick Tips For Full Spectrum Cbd Oil Uk Full Spectrum Cbd Oil For Sale Uk
My developer is trying to persuade me to move to .net from PHP.
I have always disliked the idea because of the expenses. But he’s tryiong none the less.
I’ve been using WordPress on a number of websites for about a year and am worried about switching to another platform.
I have heard fantastic things about blogengine.net.
Is there a way I can transfer all my wordpress content into it?
Any help would be greatly appreciated!
Take A Look At One Of The Repair Double Glazed Windows Industry’s Steve Jobs Of The Repair Double Glazed Windows Industry repairs to
upvc windows – https://vuf.minagricultura.gov.co/lists/informacin%20servicios%20web/dispform.aspx?id=7662164 –
zestril cost price: medication lisinopril 20 mg – zestoretic 5 mg
Greetings from Carolina! I’m bored to death at work so I decided to check out
your blog on my iphone during lunch break. I love the knowledge you provide here and can’t wait
to take a look when I get home. I’m amazed at how fast your blog loaded on my phone ..
I’m not even using WIFI, just 3G .. Anyhow, wonderful
blog!
prednisone 5mg over the counter prednisone 20 tablet prednisone 50 mg buy
prednisone over the counter cost: prednisone 20 mg pill – prednisone for sale