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
Normally, these payday loans have a cap of about $500.
legit canadian pharmacy online: online pharmacy canada – canadian medications
якщо гравець не познайомилися з визначенням спільних покупок, шорты рабочие
то воно означає Збір загального замовлення
декількох.
Here is my homepage https://eurosiz.ua/product-category/spetsodezhda/filter-tip-shorty/
pharmacies in mexico that ship to usa: mexican online pharmacies prescription drugs – mexican rx online
mail order pharmacy india п»їlegitimate online pharmacies india Online medicine order
http://foruspharma.com/# mexican online pharmacies prescription drugs
http://indiapharmast.com/# mail order pharmacy india
http://foruspharma.com/# mexican drugstore online
This Is The Good And Bad About Bunk Beds For Adults Edda Fay
п»їbest mexican online pharmacies: mexican border pharmacies shipping to usa – buying prescription drugs in mexico online
Hey great website! Does running a blog like this take a great deal of work?
I have no knowledge of coding but I was hoping to
start my own blog in the near future. Anyways, should you have any ideas or tips for new blog owners please share.
I know this is off subject nevertheless I simply had to ask.
Thanks!
adderall canadian pharmacy canadian family pharmacy canadian pharmacy mall
canadian pharmacies online: global pharmacy canada – canadian pharmacy meds
Are You Responsible For An Best Pushchair Budget?
10 Ways To Waste Your Money 037810.xyz
Thanks a lot. Plenty of posts.
my page – https://Nilecenter.online/blog/index.php?entryid=989108
You’re so cool! I do not think I have read through anything like this before.
So nice to find another person with some unique thoughts on this issue.
Seriously.. thanks for starting this up. This website
is one thing that’s needed on the internet, someone
with some originality!
cheapest pharmacy canada: canadian drugs – safe canadian pharmacies
magnificent submit, very informative. I wonder why the other experts of this sector don’t notice this.
You must proceed your writing. I am sure, you have a great
readers’ base already!
Hi, its good piece of writing on the topic of media
print, we all know media is a wonderful source of facts.
Here is my web page … 인천출장마사지
safe reliable canadian pharmacy: canada rx pharmacy – canadian compounding pharmacy
canadian pharmacy 24: legitimate canadian pharmacy online – best canadian online pharmacy
indian pharmacy online pharmacy website india indian pharmacies safe
Lyons explіcitly referгed to the սnclear Ηonest launch wherеas doіng
ѕo. The primary critic to select up on Clark’s statements ԝas аt the liberal
media watchdog group Fаirness and Accuraсy in Reⲣorting (Honest).
Copyright 2024 Grey Media Groᥙp, Inc. All rights reserved.
“And the argument is always ‘it still makes telephone calls,’” Warmenhoven said.
It should be also remembered there remains to be no scientific еvidence
of dangerous results of cell pһones. “courtesy” of Google
translator and my oԝn corrections of the nonetheless сlumsy wߋrk of the Goⲟgle translator…
A necessary a part of your question is that STUK ought to educatе cell phone
customers, to a greater extent, also about expoѕurеs caused by the data switch.
Fіnally, one ϲould ask a query whether or not this, ‘arbitrary hidіng data by STUK’,
displays more broadly on ԝhat is the secսrity cսlture at SƬUK.
In line with Bluetooth, greater than fiνe biⅼlion new Bluetooth units might be shipped this
12 months, including to the billions of units already in usе and
making it a tempting goal foг fraudsters.
Also vіsit my blog – pu adaptor
http://foruspharma.com/# mexican rx online
10 Basics To Know 2 In 1 Pram You Didn’t Learn In School Baby pushchair 2 in 1
buy medicines online in india: indian pharmacy paypal – Online medicine order
canadian pharmacy online reviews: canadian pharmacy mall – canadian pharmacy mall
reputable indian pharmacies: mail order pharmacy india – indian pharmacy paypal
Howdy! This post could not be written any better!
Looking through this post reminds me of my previous roommate!
He constantly kept preaching about this. I will forward this article
to him. Pretty sure he’ll have a very good read. Thanks for sharing!
Five Killer Quora Answers On Small Sleeper Sectional Couch small sleeper sectional