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
14 Common Misconceptions Concerning Certified Slots Online slots – olderworkers.com.au –
Slot Tours: The Secret Life Of Slot Tours hacksaw slots Online casino (nuriteck.com)
сериал смотреть полностью
I’m not sure why but this blog is loading very slow for
me. Is anyone else having this problem or is it a problem on my end?
I’ll check back later and see if the problem still exists.
From All Over The Web Twenty Amazing Infographics About Online Shopping Sites In United Kingdom 5×40 white gloss car wrap
Thanks designed for sharing such a pleasant opinion, piece of writing is nice,
thats why i have read it entirely
Five Slot Strategies Lessons From Professionals Slot Strategy
I think this is one of the most important information for
me. And i am glad reading your article. But wanna remark on few general things, The web site
style is great, the articles is really great : D. Good job,
cheers
My brother suggested I might like this blog. He was entirely right.
This post truly made my day. You cann’t imagine just how much time I had spent for this information! Thanks!
I was recommended this website by my cousin. I’m not certain whether this post is written by him as no one else recognize such specific about
my difficulty. You’re wonderful! Thank you!
The Reason Why You’re Not Succeeding At Classic
Casino Slots Modern Slots
Double Glazing Near Me: What No One Has Discussed double Glazing window handles
10 Misconceptions Your Boss Has Concerning Window Screen Replacement Replacement Window
Yes! Finally someone writes about Source.
Undisputed Proof You Need Double Glazing Fitters Near Me double glazing installers
It’s amazing to pay a visit this web page and reading the views of all colleagues on the topic of this post, while I am also zealous of getting
experience.
The Most Significant Issue With Upvc Window Repairs, And How You Can Solve
It Upvc Window Repairs Near Me
The 12 Most Popular Jackpot Slots Accounts To Follow On Twitter
video poker slots
15 Gifts For The Slot Demo Pragmatic Lover In Your Life pragmatic play demo
Бесплатная программа Wasender 1500 –
рассылка в whatsapp для массовой рассылки в
ватсап
Preventing burst pipes is always the best way tto lower repair costs.
valtrex on line
Since the admin of this website is working, no question very
soon it will be famous, due to its feature contents.
Drug information leaflet. Drug Class.
buying azathioprine prices
Some about medicine. Read information here.
My coder is trying to convince me to move to .net
from PHP. I have always disliked the idea because of the
costs. But he’s tryiong none the less. I’ve been using WordPress on a variety of websites for about
a year and am anxious about switching to another platform.
I have heard fantastic things about blogengine.net.
Is there a way I can transfer all my wordpress posts into it?
Any kind of help would be greatly appreciated!
Ten New Slots Online-Related Stumbling Blocks You
Shouldn’t Post On Twitter land-Based slots
Responsible For A CS GO Cases To Open Budget?
12 Ways To Spend Your Money Case gamma
How The 10 Worst Online Sites For Shopping In Uk-Related FAILS Of All Time Could Have Been Prevented green striped motorized awning
голые
купить аттестат ukr-diplom.ru .