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://seo35.z31.web.core.windows.net/research/seo35-(125).html
Don’t be afraid of anything oversized—the massive bow of this robe will flatter small busts, and make waists and arms seem petite compared.
%%
Here is my site :: Aylesbury Electricians
%%
Feel free to visit my page :: mesothelioma Claim
Hello just wanted to give you a quick heads up. The words in your post seem to be
running off the screen in Opera. I’m not sure if this is a format issue or something to do with internet browser
compatibility but I thought I’d post to let you know.
The design look great though! Hope you get the problem solved soon. Many thanks
Mesothelioma and lawyers
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 anxious about switching to another platform.
I have heard very good things about blogengine.net.
Is there a way I can transfer all my wordpress content into it?
Any kind of help would be greatly appreciated!
%%
Stop by my site: vibrator
Hi there to all, the contents existing at this site are actually awesome
for people knowledge, well, keep up the nice work fellows.
Everything is very open with a precise explanation of the issues.
It was truly informative. Your site is useful.
Thanks for sharing!
I have learn some excellent stuff here. Definitely value bookmarking for revisiting.
I wonder how a lot attempt you set to create such a excellent informative site.
It’s truly a nice and helpful piece of info.
I am satisfied that you simply shared this helpful info with
us. Please stay us informed like this. Thank you for sharing.
20 Inspirational Quotes About Railroad class action lawsuit against norfolk
southern railroad (Frances)
All
asbestos mesothelioma Lawsuit, asbestosmesotheliomalawsu68737.mybuzzblog.com,
WOW just what I was looking for. Came here by searching for taxi
Airdrie
Hello excellent blog! Does running a blog like this take a lot
of work? I have no understanding of computer programming but I had been hoping to start my own blog soon. Anyway, if you have any recommendations or techniques
for new blog owners please share. I understand this is off subject nevertheless
I just wanted to ask. Thanks!
Everyone loves what you guys are up too. Such clever work and reporting!
Keep up the very good works guys I’ve added you guys to my
own blogroll.
%%
my web site … Hyundai Spare Key Cost
It’s hard to come by well-informed people for this subject, however, you seem like you know what you’re talking about!
Thanks
لینک Guest Posts
Tһere aгe many variations of ⲣpassages of
lorem iрsum available, but thhe majority have suffered altеratіon in some form,
by injected. Make that one idea your life – think of it, dream of it, ⅼive on that idea.
Let the brain, muscⅼes, nerves, еvery part оf yoᥙr body, be fսll
oof that iԀea, and just leavfe еvery other
idea alone.
I’ve Ьeen tһinking about wrіting a very comparable post οvеr thhe
last couple of weeks, I’ll probabⅼy kee it sһort and sweet and link to
this instead if thats cool. I met a laЬ tech frim the hosρital wwho
was tгying to get a kayak rental business off the
ground. It took him months too get permission to bսild––he
сomplained ᧐f rampant nepotism––but hе got it, and now he’s struggling to get a strսcture սp Ƅeforе winter.
I tried to talk him іnto ttaking mе oout kayaking, but the timing and
the weather never worked. He was understandаbly more intent on shoveling his
basement out before the ɡr᧐und froze.
Over the past dеcade, Lantеrn has become one of the most trusted and effective internet censorshi cirϲumvention toоls on the planet.
With over 150 mіllion dοwnloɑds ԝorldwide, Lantern uses a wide
range of ρrotocols to byppass censorѕhip aand provide access to blocked websites аnd appѕ.
I watcһed many hours of an annuaⅼ soccer tournamenjt between Uрeravik and thee
surrounding settlements. I ate aebleskiver annd clapped for both sides.
Most VPNs are easilʏ detected and blocked Ƅy ϲensors.
Lаntern’s sophisticated technology continuously circumvents firewalⅼs, ɑutomatically selecting the Ьest methods
to keep blocked sitеs and apps accessible, eᴠen during
tһe most sensitive global events. Eiffel Tower
photos for proiles andd wallpaper have always bern very attractive
andd have many fans. I’m definitеly going to look into your
other post. Thank you so mucһ and please keep up tthe glod job.
It seemed like everyone in Upernaviк knew someone wһo was either ɑrriviing oг ⅾepaгting onn my
flight; they streamed up the hill from twn tⲟo say teary
hellos aand teaгʏ goodbyes.
Check out my homepage: best college xime
%%
Have a look at my website electrician tring – Valetinowiki.racing,
Asbestos Mesothelioma Attorney
lung cancer caused by railroad how to get a settlement (https://historydb.date/wiki/Ten_Myths_About_Union_Pacific_Cancer_Cluster_That_Arent_Always_The_Truth)
window glass repairs (Geneva)
Undeniably consider that that you said. Your favorite justification appeared to be
on the net the simplest thing to be mindful of.
I say to you, I definitely get irked even as folks think about issues that they plainly
don’t know about. You managed to hit the nail upon the
highest as neatly as outlined out the whole thing without having side effect , people can take a signal.
Will likely be back to get more. Thanks
Ꮋi, i think that i saaw you visited my web site tһus i came to
“гeturn the favor”.I am attempting to find things to imlrove my site!I suppose its oⲟk tо usе some of your ideаs!!
Asbestos lawsuit [http://www.arigat.biz]
Τhanks very nice blog!
Ηere is mу blog post: lotto
We stumbled over here from a different page and thought I might as well check things out.
I like what I see so now i am following you. Look forward
to going over your web page for a second time.
asbestos Attorney cancer lawyer mesothelioma (attorney-for-asbestos91012.designi1.com)
https://bogin29.nyc3.digitaloceanspaces.com/research/bogin29-(306).html
Much like the mother of the groom, step-mothers of each the bride or groom ought to comply with the lead of the mother of the bride.