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
best online pharmacies in mexico
https://cmqpharma.com/# п»їbest mexican online pharmacies
mexico drug stores pharmacies
lesbian porn
Improve Your Page Rank With Keyword Modifiers 구글 상위노출 백링크
You’ll Never Guess This Upvc Window Repair’s Secrets upvc window Repair
Consolidation Loan Debt – What Does It Have? 학자금 대출
can you buy mentat without prescription
15 Top Twitter Accounts To Find Out More About Claims For Asbestosis http://www.9363280.xyz
Hi there to every one, it’s genuinely a pleasant for me to pay a quick visit this web page, it
includes important Information.
mexico drug stores pharmacies
https://cmqpharma.com/# purple pharmacy mexico price list
mexican online pharmacies prescription drugs
doxera.icu
good rx lisinopril hctz
buying prescription drugs in mexico online
https://cmqpharma.com/# medication from mexico pharmacy
п»їbest mexican online pharmacies
Интернет магазин металлов с цветных а также чёрных металлов “STORM”
https://stormbrand.ru/
10 Mobile Apps That Are The Best For Malpractice Law malpractice Attorney
where can i get lexapro no prescription
It is appropriate time to make a few plans for the longer term and it’s time to be happy.
I have learn this put up and if I could I wish to recommend you some interesting
issues or tips. Perhaps you could write next articles relating
to this article. I desire to learn more issues about it!
My blog; Houston copiers
Wonderful article! Τhat is tһe type of infoгmation tһɑt arе supposed
to be shared аround tһe web. Disgrace on tһe serch engines for now not positioning this pᥙt up
һigher! Come оn over and consult wіth my site . Τhank you =)
Here is my web-site: jasa backlink pyramid
Someone essentially lend a hand to make severely articles I’d state.
That is the very first time I frequented your web page and up to now?
I amazed with the analysis you made to create
this actual submit extraordinary. Wonderful activity!
Магазин металлов с разноцветных (а) также чёрных металлов “STORM”
https://stormbrand.ru/
medicine in mexico pharmacies
https://cmqpharma.com/# medication from mexico pharmacy
buying prescription drugs in mexico
Great post however I was wondering if you could
write a litte more on this topic? I’d be very grateful
if you could elaborate a little bit further. Thank you!
Slot Zeus Hades Demo: 11 Thing You’re Not Doing oscarreys.top
pharmacies in mexico that ship to usa
https://cmqpharma.online/# mexico drug stores pharmacies
best online pharmacies in mexico
You’ll Never Guess This Medical Malpractice Settlement’s Tricks medical malpractice (Dominik)
The One 10 Kilo Washing Machine Trick Every Person Should
Be Able To http://www.023456789.xyz
Getting Method Seo Links – Simple And Free Way 구글 검색엔진최적화
Hey there! I’m at work surfing around your blog from my new iphone!
Just wanted to say I love reading through your blog and look forward
to all your posts! Keep up the excellent work!
lesbian porn
11 Ways To Fully Redesign Your Get Diagnosed With ADHD 9326527.xyz
mexico pharmacies prescription drugs
https://cmqpharma.com/# buying prescription drugs in mexico
purple pharmacy mexico price list