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
Great insights into roofing jobs! Can anyone recommend a reliable roofers near me
Five Toledo Birth Injury Attorneys Lessons From The Professionals injury lawyer
Love seeing our community support local businesses like hardworking #roofing contractors#! roof replacement St. Louis
Drugs information. Drug Class.
promethazine hydrochloride and codeine phosphate syrup 6 25 mg
All what you want to know about medication. Read here.
https://generic51.ru/kombinirovannye/super-tadarise-sialis-20-mg-dapoksetin-60-mg
Jiu-jitsu has entirely transformed my health and fitness trip! If you’re curious concerning exactly how to get going or enhance your video game, look into the useful sources at no gi jiu jitsu
I am truly thankful to the holder of this website
who has shared this enormous article at here.
This is quite enlightening. Check out عمل پی ار کی for more
купить диплом института в кемерово prema-diploms.ru .
how can i get generic urispas without dr prescription
Viagra online price: buy viagra online – Cheap generic Viagra online
Appreciating the time and energy you put into your site and detailed information you provide.
It’s awesome to come across a blog every once in a while that isn’t the same out of date rehashed material.
Wonderful read! I’ve saved your site and I’m adding your RSS feeds to my Google account.
A Quick Guide To Being A Guarantor To Obtain Home Loan 다바오 머니 상
10 Locations Where You Can Find Mobile Automobile Locksmith mobile automotive locksmith
Appreciate the helpful advice. For more, visit pool installation in paterson
загранпаспорт стоимость [url=https://guryevsk.forum24.ru/?1-4-0-00000570-000-0-0-1735286442]https://guryevsk.forum24.ru/?1-4-0-00000570-000-0-0-1735286442[/url] .
where can i buy generic motilium price can i get cheap motilium without prescription can i get generic motilium for sale
can i order motilium pill how can i get motilium tablets can i get generic motilium without insurance
where to get generic motilium pill
where buy cheap motilium pill buy generic motilium no prescription buy cheap motilium without insurance
get generic motilium tablets buying generic motilium pills where buy cheap motilium no prescription
magnificent publish, very informative. I wonder why
the opposite experts of this sector do not realize
this. You must proceed your writing. I am sure,
you have a huge readers’ base already!
Order Viagra 50 mg online: buy viagra online – buy Viagra online
7 Great Spring Vacation Travel Destinations 하이오피사이트
загранпаспорт быстро загранпаспорт быстро .
Thanks for finally writing about > JS 依照元素出現數量排序 – 馬老師 雲端研究室 < Liked it!
It’s amazing how chiropractic care can help with pain relief after an accident! I discovered some great resources at Lakewood WA Chiropractor that others might find useful too
Hmm it appears like your site ate my first comment (it was extremely
long) so I guess I’ll just sum it up what I wrote and say,
I’m thoroughly enjoying your blog. I as well am an aspiring blog blogger but I’m still new to the whole thing.
Do you have any tips for beginner blog writers? I’d definitely appreciate
it.
10 Things Everyone Has To Say About Search Engine Optimisation Agency Search Engine Optimisation Agency seo agency london (https://ai-db.science/)
How To Obtain New Business GOLDPAY
cheapest ed pills cheap cialis п»їed pills online
This post has inspired me to prioritize my spine health! Anyone know a good chiropractor in Kent Auto Injury chiropractor
купить диплом кемерово купить диплом кемерово .
ответственность за купленный диплом 4russkiy365-diplomy.ru .