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://cytotec.club/# cytotec online
lisinopril 20 mg canadian zestoretic 20 25 mg price of zestril
10 Wrong Answers To Common What CSGO Cases Have Butterfly Knives Questions Do You Know The
Right Answers? operation Riptide Case
ciprofloxacin generic price cipro online no prescription in the usa ciprofloxacin
15 Unquestionably Good Reasons To Be Loving 18-Wheeler Accident Attorney Near Me 18 Wheeler Accident Lawsuits
cheapest price for lisinopril lisinopril 10mg tablet lisinopril 20mg prices
cipro for sale ciprofloxacin 500mg buy online buy cipro online
https://ciprofloxacin.tech/# п»їcipro generic
10 Things We All Do Not Like About Key Car Replacement lost car keys replacement cost uk
Repairs To Upvc Windows Explained In Less Than 140 Characters window repairs
In fact no matter if someone doesn’t know after that its
up to other people that they will help, so here it takes place.
propecia generic buying propecia without a prescription cost of propecia
My brother recommended I might like this web site.
He was totally right. This post actually made my day.
You can not imagine simply how much time I had spent for this information!
Thanks!
20 Insightful Quotes On Espresso Machines coffee for espresso machine
https://nolvadex.life/# tamoxifen hair loss
http://lisinopril.network/# price of lisinopril 5mg
https://cytotec.club/# buy cytotec pills
Learn About Robot Vacuum’s While Working From The Comfort Of Your Home Vacuum Mops
Five Things You’re Not Sure About About Saab 9-3 Replacement Key lost saab keys
How To Create An Awesome Instagram Video About Wall Mounted Electric Fire Electric Wall Fireplace
10 Ways To Create Your Treadmill Used For Sale Empire treadmill for sale (Jame)
lisinopril sale buy lisinopril 10 mg online lisinopril 20mg discount
How Double Glazed Door Repairs Near Me Became The Top Trend On Social
Media double glazing repair
10 Things That Your Family Taught You About Cerebral Palsy Lawsuit Cerebral Palsy Lawsuit
lisinopril 40 mg tablet lisinopril average cost prinivil 20mg tabs
The 10 Scariest Things About Designer Handbags Black
designer handbags black (teafish.cc)
tamoxifen breast cancer prevention tamoxifen bone pain femara vs tamoxifen
get cheap propecia tablets cost of generic propecia without dr prescription cost of cheap propecia without insurance
It lets advertisers bid for commercials placed in sponsored hyperlinks of the search engine when someone
searches on a key phrase that’s relevant to their
enterprise. For this web page, we have constructed all links from high area authority websites
and seen improvements when we construct the first link. You’ve gotten seen many emails coming by as spam
day by day. Bending or V-like shapes might be achieved by incorporating double
bonds, that can bear cis-trans isomerization in response to sure stimuli (typically irradiation with a suitable wavelength), as seen in numerous designs consisting of
stilbene and azobenzene items. C6H5NH2. Consisting of a phenyl group (−C6H5) hooked up to an amino group (−NH2), aniline is the only aromatic amine.
By regulation, any such amendment 1) is limited to a single subject, 2) should embody a ballot title
not to exceed 15 phrases in length, 3) should additionally embody a ballot abstract to not exceed seventy five phrases in length, and 4) must additional include a monetary influence assertion to not exceed seventy five words in size..
Except as noted beneath, all amendments proposed, regardless of the strategy of
proposal, have to be permitted by 60 p.c of the voters in a referendum held simultaneously with the next normal election (that’s, the next one a minimum of ninety days after the modification is filed with the custodian of
state data) earlier than they become part of the Constitution.
30 Inspirational Quotes For Double Glazed Units Near Me Double Glazed Windows – Talley-Bridges-2.Blogbright.Net –