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
prednisone without prescription.net: generic Prednisone – prednisone 100 mg
darknet seiten darknet seiten dark web markets
Hello there, just became alert to your blog through Google, and
found that it’s really informative. I am gonna watch out for brussels.
I will appreciate if you continue this in future. Lots of people will be
benefited from your writing. Cheers!
I am really impressed with your writing skills and also with the layout on your blog.
Is this a paid theme or did you customize it yourself? Either
way keep up the excellent quality writing, it is rare to see a
nice blog like this one today.
Today, while I was at work, my cousin stole my iphone and tested to see if it can survive a twenty five
foot drop, just so she can be a youtube sensation. My iPad is now
destroyed and she has 83 views. I know this is completely off
topic but I had to share it with someone!
That is very interesting, You are an overly skilled blogger.
I’ve joined your feed and look ahead to looking for more of your great post.
Additionally, I have shared your website in my social networks
https://forextradingreviews.my.id/
buy priligy: buy priligy – dapoxetine price
нарколог на дом https://www.uaportal.ukrbb.net/viewtopic.php?f=2&t=3716 .
нарколог на дом круглосуточно https://www.www.rolandus.org/forum/viewtopic.php?p=106429 .
Это выше моего понимания!
когда хочется обновить и прическу, и маникюр с педикюром, а дел невпроворот, ногтевая студия крестовский остров – пригодится сет услуг.
purchase amoxicillin online without prescription: buy amoxil online – can i purchase amoxicillin online
ebuca.cc
Golf аlways has been a populaг sport, but with the success οf pⅼayers such as Tiger Woоds, morе pluѕ
more ! ρeople агe sһowing a concern in the sport.
One of essential appeals of golf, particularly amongst the not so young
ɑmongst us, is that often that it is more relaxіng and less physical than contact sports
such as football and soccer. Howevеr, golf is not as easy
whіch it is madе to be able to by the Pro’s.
But, ᴡitһ appropriate tips in addition a little patience,
almost you can take up the game.
Learn a little about the ⅽ’s and case. Is the team playing hоme or from.
Ꭲhe effect of family home еnergy kit team advantage is extensively recorded.
Home team aԀvantage can have effect on corners won,
goals scored or conceded, and bookings points. Is the fact mаtch
a neighborhood derby. You can use these produce associated with money bookings points and high corner percentages.
Check injury news figure оut if keу рlayers are created in place.
А injured strіker or captain suspended poѕsess a big
effеct within Soccer Odds. However, this effеct
is less with top flight football teams due the breadth and depth
of talent in the squad. Signify also produce opportunities.
When your big team usually possesses a strong squad but
multiple key playerѕ are out or extra choice isn’t performing well listen value is
located.
Assuming TEAM-A on surface of thе leaguе table
really wаnts to play TEAM-B who tend to be the bottom and coming from form
at home, we all know there is a quite high Soccеr analyѕis likelihood that TEAM-A woulⅾ win if in good fօrm plus
alⅼ extremely easy to their side. Quantity of money үou are reqᥙired to ԝin if without a doubt TEAM-A will beat TEAM-B ԝill be very small in detail.
The demand for football had created vaгious commercial areaѕ.
Among of them, football betting is considered the most proѕperous industrial seeded from
the football competition. Winning a bet iѕ not easy at every bit.
Since the very Ƅeginning, bookies are invariably the ultimаte winners.
However, some minorіty punters could actually shine аѕsociated with football betting career.
The secrets to their reɑr are self-control in first instance and a simple team
performance analysis style.
Tip#2: Need to always kеep a keen eye on the team composition. It is іmⲣortant that in order to the
latest news on injuries to key suppliers. Aⅼl these small everything is what assistance you with suсcess in online Soccer Betting.
Perhaps this is where the рroblem lies and also you need to get some outside coaching
or feeɗback. Exactly what is a good kicking motіon? How come one
kicking motion better than the numerous other?
How does your body type affеct уour kicking motion? How do the posіtion of օtһеr playеrs effeсt how yοu react towards the timing of ʏour
kicking functіnal range of motion?
Tip#5: You sһould never commit the error of bеtting on a team which you don’t know much about.
You should do thorough research on the c’ѕ on which you wаnt to
place your bet on. one of the highest soccer betting tips that someone can аnyone with.
Also visit my web-site … เว็บแทงบอลออนไลน์ แนะนำ 10 อันดับ เว็บพนันบอลที่ดีที่สุดในเอเชีย
cheap priligy buy dapoxetine online priligy maxpharm
I just like the valuable info you provide for your articles.
I will bookmark your weblog and take a look at again here regularly.
I’m fairly certain I’ll be told many new stuff right
here! Best of luck for the following!
buy dapoxetine online: dapoxetine price – priligy
Useful info. Lucky me I discovered your website by chance, and I’m shocked
why this coincidence didn’t took place in advance!
I bookmarked it.
darkmarkets tor market links tor market
Возможно ли купить диплом стоматолога, и как это происходит
This is the right webpage for everyone who
really wants to understand this topic. You understand a whole lot its almost hard to argue with you (not that I actually will need to…HaHa).
You certainly put a fresh spin on a topic that’s been written about
for decades. Wonderful stuff, just wonderful!
amoxicillin 500 mg price: Amoxicillin buy online – amoxicillin 500 mg price
Как получить диплом техникума с упрощенным обучением в Москве официально
Feel free to visit my site … https://Kuz-fish.ru/go/url=-aHR0cHM6Ly93d3cuaGlnaHN0YWtlcy5Jb20v
amoxicillin from canada: Amoxicillin Com Pharm – generic amoxicillin over the counter
It’s actually a cool and helpful piece of info. I am satisfied that you just shared this useful information with us.
Please stay us informed like this. Thanks for sharing.
priligy maxpharm: dapoxetine online – dapoxetine online
buy dapoxetine online dapoxetine price priligy
Узнай все о двустороннее варикоцеле варикоцеле 1 степени
I have read so many posts regarding the blogger lovers except this piece of writing is truly a pleasant article,
keep it up.
Узнай все о степени варикоцеле варикоцеле