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
First of all I want to say superb blog! I had a quick question which I’d like to ask if you do not mind.
I was curious to find out how you center yourself and
clear your thoughts before writing. I have had difficulty clearing my mind in getting my thoughts out there.
I truly do take pleasure in writing however it just seems like the first
10 to 15 minutes are generally lost just trying to figure out how
to begin. Any recommendations or tips? Thank you!
My webpage; Study Abroad
http://canadianpharmgrx.com/# pharmacy rx world canada
The writer is called Lauren. Going to fitness is a thing
that he is totally endlaved by. He currently lives in Idaho.
Dispatching is his profession but he’s already applied for another one.
reputable mexican pharmacies online Mexico drugstore pharmacies in mexico that ship to usa
canadian 24 hour pharmacy List of Canadian pharmacies canada pharmacy online
You are so interesting! I do not believe I’ve truly read
anything like that before. So good to discover someone with genuine
thoughts on this subject. Seriously.. thank you for starting this up.
This site is something that is required on the internet, someone with
a little originality!
Thank you for some other great post. The place else may
just anybody get that type of information in such an ideal means of writing?
I have a presentation next week, and I’m on the look for such info.
Online medicine home delivery Healthcare and medicines from India mail order pharmacy india
canada pharmacy online canadian pharmacy pharmacy canadian superstore
top 10 pharmacies in india: indian pharmacy – pharmacy website india
northwest pharmacy canada Canada pharmacy online legit canadian pharmacy
free fire max diamond top up
free fire india top up
codashop free fire top up
free fire diamond top up
free fire top up
garena free fire top up
free fire diamond top up
top up free fire max
top up free fire
top-up garena free fire
free fire diamonds top up
garena ff diamond top up
top up free fire max
garena free fire max top up
garena free fire max top-up
top up ff max
free fire diamond shop
free fire max top up
garena free fire top up diamonds
free fire top up offer
codashop free fire top up
free fire diamond buy
ff diamond top up
ff diamonds top up
garena free fire max top-up
top up free fire
free fire diamonds buy
ff diamond top up
free fire max top up
free fire max diamond top up
free fire id top up
free fire account top up
free fire max top up center
top up ff max
ff max top-up
ff top up
garena topup free fire
free fire diamonds top up
free fire diamond top up
free fire top-up
free fire top up website in india
free fire top up codashop
garena top up center ff
free fire top up diamonds
free fire top up diamond
free fire top up india codashop
garena diamond top up free fire
top up diamond free fire codashop
ff max top-up
ff max top-up diamond
ff max top-up diamonds
double diamond top up codashop
free fire top up centre
free fire top up center
codashop free fire max paytm
diamonds free fire top up
diamond free fire top up
free fire special airdrop top up online
top up free fire diamond
top up free fire diamonds
codashop com free fire
garena free fire max top up center
garena free fire top-up
garena free fire topup
free fire diamond recharge
diamond top-up free fire
diamonds top-up free fire
free fire diamond top up app
free fire diamond top up
free fire diamond top up site
garena free fire diamond top up
free fire diamond top up website
monthly membership in free fire
free fire garena top up
codashop ff top up
free fire top-up website
top up in free fire
garena free fire max diamond top up
garena free fire max diamonds top up
free fire diamonds top up app
top up free fire diamonds
top up free fire diamond
free fire double diamond top up codashop
garena free fire top up center
free fire diamond purchase
free fire top up india
winzo free fire diamond top up
winzo free fire diamonds top up
free fire diamonds purchase
free fire diamond purchase
diamond top up in free fire
free fire top up diamond
codashop free fire diamond india
free fire top up app
free fire top up garena
free fire topup
shop garena sg diamond
shop garena sg diamonds
freefire topup discount
top up free fire max
top up garena free fire max
freefire topup
garena free fire top up
shop garena free fire
diamond top up free fire
top up garena free fire
freefire top up
top up game free fire
top up game free fire max
free fire online top up
free fire paytm top up
free fire top up paytm
free fire diamond topup
free fire diamond top up
top up of free fire
free fire top up site
top up for free fire
free fire top up shop
free fire top up website
garena top up centre free fire
garena ff id top up
garena top up diamond
free fire game top up
free fire top up offers
free fire diamond store
coda shop diamond ff
free fire top up link
free fire top up live
free fire top up websites
top up app for free fire
top up app for free fire max
free fire top up recharge
free fire top up shop
free fire top ups
online free fire top up
online free fire top up max
free fire top up apps
free fire top up diamond
garena free fire top up website
free fire airdrop top up online
free fire monthly membership top up
free fire diamond top up karo
diamond top up ff
seagm free fire
free fire diamond top up paytm
free fire account top up
free fire top up upi
free fire top up india
free fire official top up
top up website free fire
ggtopup free fire
seagm free fire top up
diamond top up website
ff top up codashop
free fire diamond top up garena
seagm free fire diamond
codashop free fire double diamond
seagm.com free fire
garena free fire top up centre
shop free fire top up
diamond top up website free fire
akash game shop free fire top up
seagm free fire top up india
seagm free fire india
winzo top up free fire
winzo free fire top up
game shop free fire top up
free fire top up seagm
mid shop free fire top up
codashop garena free fire top up
ff max top up
free fire diamond topups
free fire diamond topup
seagm ff top up
garena free fire max top up
garena free fire max top-up
free fire max topup
free fire max top-up
garena free fire max top up centre
online free fire max top up
free fire max top up website
top up garena free fire max
garena top up centre codashop
seagm free fire max
seagm ff max
free fire diamonds center
free fire max game top up
garena free fire max game top up
free fire max game top-up
garena free fire max game top up
garena free fire max game top-up
garena free top up
garena ff top up
gerena topup ff gamedouble diamond free firedouble diamond top upfree fire double diamonds top up
top-up garena free fire max
free fire diamond garena buy
4000 diamond top up
app free fire diamond buy
codashop free fire double diamonds
free fire rupees top up website
game top up center ff
seagm free fire max top up
free fire diamond top-ups
free fire diamond top-up
garena free fire max top up website
seagm free fire topup
seagm free fire top up
winzo free fire top up max
free fire online top-up
garena free fire max topup website
garena free fire max top up website
game shop free fire top up max
top up seagm free fire
game shop free fire max top up
top-up free fire
garena free fire max top-up website
seagm garena free fire top up
top-up website free fire
upi free fire top up
game shop free fire top-up
free fire top-ups
top up garena ff
top up garena free fire max
top up free fire
free fire max top-up
free fire top up
garena ff diamond top up
garena free fire top up
garena free fire max top up
Drugs information leaflet. Effects of Drug Abuse.
propecia without a prescription
Everything trends of medicament. Get here.
My brother recommended I might like this web site.
He was entirely right. This post actually
made my day. You can not imagine just how much time I had spent for this information! Thanks!
watch porn video
food-plastic.ru
I loved as much as you’ll receive carried out right here.
The sketch is tasteful, your authored material stylish.
nonetheless, you command get bought an shakiness over that you wish
be delivering the following. unwell unquestionably come further formerly again as exactly the
same nearly very often inside case you shield this increase.
I loved as much as you’ll receive carried out right here. The
sketch is attractive, your authored material stylish.
nonetheless, you command get got an nervousness over
that you wish be delivering the following. unwell unquestionably come further formerly again since exactly the same nearly a lot often inside case you shield this increase.
Wonderful web site. Lots of helpful information here.
I’m sending it to some pals ans additionally sharing in delicious.
And of course, thank you to your sweat!
hi!,I love your writing very so much! percentage we be
in contact extra approximately your article on AOL? I require an expert
in this space to resolve my problem. May be that’s you! Looking forward to look you.
reputable mexican pharmacies online: mexican mail order pharmacies – mexican drugstore online
mexican drugstore online Pills from Mexican Pharmacy mexican pharmaceuticals online
My brother recommended I might like this website design billings.
He was totally right. This post actually made my day. You cann’t imagine simply
how much time I had spent for this information! Thanks!
reputable indian pharmacies: top 10 online pharmacy in india – Online medicine home delivery
Hello there! I know this is kinda off topic but I’d figured
I’d ask. Would you be interested in trading links
or maybe guest writing a blog article or vice-versa? My site covers a lot of
the same subjects as yours and I believe we could greatly benefit from each other.
If you might be interested feel free to send me an e-mail.
I look forward to hearing from you! Great blog by the way!
indian pharmacies safe Healthcare and medicines from India indian pharmacy
mexican drugstore online mexican pharmacy mexican pharmacy
5 Clarifications On Ford Car Key Ford Kuga Key Replacement
Woah! I’m really digging the template/theme of this blog.
It’s simple, yet effective. A lot of times it’s tough to
get that “perfect balance” between superb usability and
visual appearance. I must say you’ve done a very good job with this.
In addition, the blog loads very quick for me on Opera.
Outstanding Blog!
fm-saveli.ru