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
Medicines information. Effects of Drug Abuse.
where to buy compazine without prescription
Some what you want to know about medicament. Read information here.
You’ll Never Guess This Walking Pad Under Desk’s Benefits walking pad under desk (https://daek.kr/free/325980)
I for all time emailed this webpage post page
to all my associates, since if like to read it after that my links will too.
When someone writes an article he/she keeps the thought of a user in his/her brain that
how a user can understand it. Thus that’s why this paragraph is great.
Thanks!
https://prodvizhenie-himki.ru/
where buy cheap inderal price
From Around The Web Here Are 20 Amazing Infographics About Infant Car Seats Infant Car Seats Cheap
Article writing is also a excitement, if you know after that you
can write otherwise it is complicated to write.
Watch Out: How Male Masturbation Toy Is Taking Over And What To Do About It top male masterbators
Hmm is anyone else encountering problems with the
pictures on this blog loading? I’m trying to figure out if its a problem on my end or if it’s the blog.
Any responses would be greatly appreciated.
A Comprehensive Guide To Bunk Bed With Double Bed.
Ultimate Guide To Bunk Bed With Double Bed double size bunk bed (zv4bu3suvat3e.com)
Meds prescribing information. Effects of Drug Abuse.
where can i buy ramipril without a prescription
Actual about pills. Get here.
Superb, what a web site it is! This webpage presents
helpful data to us, keep it up.
I’m extremely impressed with your writing skills and also with the layout
on your weblog. Is this a paid theme or did you modify it yourself?
Either way keep up the excellent quality writing, it’s rare to see a great blog like this
one nowadays.
My web blog … wilkinson chute parts
Ten Coffee Bean Machines That Really Improve Your Life
Coffee Bean machines
I am really grateful to the holder of this web site who has shared this enormous article at here.
Аренда гидроцикла.
Большой выбор гидроциклов в аренду от собственника.
На сервисе arendakatera.pro вы можете сдать или взять в
аренду гидроцикл
Decide funding for the upcoming motor vehicle or refinance with self esteem.
Take a look at currently’s car financial loan costs.
Time for you to first payment: After you offer a product, anticipate a wait duration of
all-around 5 times to get money within your checking
account on most platforms.
There’s no justification for working away from
money any more. Nicely, many of us mess up in some cases, but
there’s no purpose you shouldn’t be able to conjure up a couple of hundred dollars away from slender air for those
who’re prepared to get Inventive regarding how to
make money.
Not everyone seems to be courageous adequate to hire out their total residence to your
stranger, but even leasing out the spare space can offer a large supply of excess
money. You may perhaps meet some attention-grabbing
individuals and find yourself enjoying it.
In the same way, if you’ve attained past success on the planet of entrepreneurialism,
your services could be of use to budding business people as well as established business people who
want to consider their organization to the subsequent amount.
Everybody knows that therapy is actually a hugely-expert and hard occupation, although not Lots of people realize it’s
shifting online.
A different crucial element of promoting and advertising is casino starting off
a good email promoting system, which helps to keep
customers and change prospects.
You may also make money fast by completing surveys, microtasks, rewards plans, or
any of the other simple tips on this checklist. The quantity you’ll get won’t be high, but It’ll be quick.
In addition to supporting organizations to deal with their social
accounts, you’ll be able to give them advice regarding
how to sort a protracted-expression social websites strategy.
Should you aren’t excited about working with a pc all day, Check out a
lot of the finest methods to make money offline:
Engaging in liable gambling with bonus resources and
managing them as authentic money can cause greater determination-making
along with a simpler reward system.
Choose in for bonus resources. As many as 50x wagering, recreation contributions differ, max.
stake applies, new customers will have to decide in and claim offer in just 24
hrs and use inside thirty days. Geographical Limits and T&Cs
I’m not sure if it’s intentional or an editorial remark, though the pitch for blogging claims “Is there
a topic or subject matter you’re really experienced about and luxuriate in adequate to have the ability
to create on it each day For some time?
That compensation impacts the location and buy by which the manufacturers are offered and is some scenarios may impression the rating that may be assigned to them.
MONEY
FREE CASH
CASINO
PORN
SEX
ONLY FANS
This is my first time pay a visit at here and i am actually happy to read all at alone
place.
I was recommended this web site by my cousin. I’m not sure whether this post is
written by him as nobody else know such detailed about my difficulty.
You’re wonderful! Thanks!
When I initially commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four
e-mails with the same comment. Is there any way
you can remove people from that service? Thank
you!
my page; the growth matrix results
Why people still make use of to read news papers when in this technological
world everything is accessible on net?
Dernière sortie incontournable de mars, Anna Et Le Prince
D’Albion parle de vengeance, de combat et de romance.
Voici une romance de Yûki Kodama qui vous touchera,
traitant du travail magnifique et artisanal de
la porcelaine. Adaptée du manga éponyme de Hitsuji Gondaira,
cette production de SILVER LINK mêle action, comédie et même romance.
Un homme, Misato Otomo, survit miraculeusement après cette catastrophe.
Pour beaucoup, Spice & Wolf est un anime de 24 épisodes,
diffusé entre 2008 et 2009. D’autres penseront
à la série de light novels, au manga de Keito Kōme, également sorti en 2008, ou
encore aux jeux vidéos sortis en 2019. Pour autant,
ce remake réalisé par le studio Passione (Citrus,
Mieruko-chan) promet un regard plus moderne sur
cette histoire. Si l’une d’entre eux, Ena, propose une soirée camping luxueuse dans son jardin, Rin semble
avoir d’autres plans. Pour autant, le cœur de l’animé reste le même, avec du camping et beaucoup d’humour
au programme. Un bon programme pour patienter jusqu’à l’année prochaine pour en découvrir de nouvelles.
Celui-ci ne voit justement pas d’un très bon œil
la relation entre sa sœur et Taiyou, qu’il veut même éliminer.
Dans le genre des animes qui représentent parfaitement le printemps et son esprit chaleureux, Yuru Camp est
un bon représentant.
Post writing is also a excitement, if you be
familiar with then you can write or else it is
difficult to write.
mtpolice.kr provides sports betting information, sports analysis, and sports tips
as a sports community.
Good post. I learn something totally new and challenging on websites I stumbleupon on a daily basis.
It will always be useful to read through content
from other authors and use a little something from their web sites.
9 Lessons Your Parents Taught You About Mesothelioma Claim mesothelioma
Do you mind if I quote a few of your posts as long as I
provide credit and sources back to your site?
My blog is in the very same niche as yours and my visitors
would truly benefit from some of the information you present here.
Please let me know if this alright with
you. Cheers!
Really all kinds of wonderful data.
Why Nobody Cares About Mesothelioma Lawsuits mesothelioma settlement lawyer