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
Anabolika kaufen 24 erfahrungen anavar, dianabol kur absetzen Home
› Forums › Ask Me Anything › god steroidkur This topic contains 0 replies, has 1
voice, and was last updated by SusanUO 11 months, 4 weeks ago.
Sie wollen Ihre Erfahrungen mit Analdusche teilen? Diese
Erkenntnis entstammt unserer wissenschaftlichen Durchdringung des Gegenstandes „Kampf” und unseren in über 50 Kampfkunstjahren gemachten und reflektierten Erfahrungen. • Reduktion der Komplexität durch anfängliche Reduktion der Distanz und Arbeiten „Körper-an-Körper”, um
eine gewisse Ordnung in das scheinbare Chaos des Kampfes zu bringen oder sie dort zu erkennen. • das Kernspecht’sche Gestängemodell statt unsinniger.
Ein Selbstverteidigungsunterricht muss sich an diesen fünf Angriffsphasen orientieren, statt
blauäugig und weltfremd die Schüler auf Angriffe vorzubereiten,
die nur im eigenen Stil vorkommen (z.B. Daraufhin überprüfte er die
überlieferten Unterprinzipien (z.B. Aber
ihnen wird es gehen wie dem, der sich zu Hause witzige Antworten einpaukt,
damit er bei seinem ersten Date schlagfertig erscheint. Gibt es ein Ereignis, das Ihnen in besonderer Erinnerung geblieben ist?
Please let me know if you’re looking for a article writer for
your site. You have some really good posts and I feel I would be
a good asset. If you ever want to take some of the load off, I’d
absolutely love to write some material for
your blog in exchange for a link back to mine. Please shoot me an email if interested.
Regards!
Hi there, I enjoy reading through your article post. I
wanted to write a little comment to support you.
It’s really a cool and helpful piece of info.
I am glad that you simply shared this useful information with
us. Please keep us informed like this. Thanks for sharing.
Yes! Finally something about http://www.drugoffice.gov.hk/gb/unigb/bvkrongbong.com/Default.aspx?tabid=120&ch=514505.
It’s remarkable designed for me to have a web site, which is useful in support of my experience.
thanks admin
You could definitely see your expertise in the work you write.
The sector hopes for more passionate writers like you who
aren’t afraid to mention how they believe. Always follow your heart.
Howdy! This article couldn’t be written any better!
Looking at this post reminds me of my previous roommate!
He continually kept preaching about this. I’ll send this information to him.
Fairly certain he will have a great read. Many thanks for sharing!
Good post! We are linking to this great post on our website.
Keep up the good writing.
Informative article, exactly what I was looking for.
If some one needs to be updated with latest technologies then he must be visit this website and be up to date every day.
Hi it’s me, I am also visiting this site daily, this
website is genuinely good and the visitors are really sharing
fastidious thoughts.
Hello there, I found your web site via Google even as searching for a comparable matter, your web
site came up, it looks great. I have bookmarked it in my
google bookmarks.
Hi there, just was aware of your weblog via Google, and found
that it is truly informative. I am going to be careful for
brussels. I will appreciate should you continue this in future.
Lots of other folks will likely be benefited from your writing.
Cheers!
Ob bei Produktion, Nutzung und Entsorgung diverse Schadstoffe wie Weichmacher, BPA, PAKs et alia
austreten, hängt dann noch vom jeweiligen Plastikbaumproduzenten ab.
Bio-Weihnachtsbäume sind eine Alternative,
neben anderen die auch langjährige Nadel-Fans zufrieden sein können. Beim Bio-Weihnachtsbaum gibts all das nicht … Entgegen die konventionellen wachsen die Bio-Weihnachtsbäume in Mischkulturen. Stattdessen halten oft Schafe die Pflanzen zwischen den Bäumen kurz.
Alternative Bio-Weihnachtsbäume aus ökologischen Christbaum-Kulturen erkennst du an Siegeln der Bio-Anbauverbände, erst recht dem EU-Biosiegel, dem Biokreis-Siegel, dem Bioland-Siegel, dem Demeter-Siegel und dem Siegel von Naturland.
Das macht sie weniger anfällig für Schädlinge und die Flächen werden wie bei Bio üblich nicht mit Herbiziden bespritzt.
Kunstdünger und chemisch-synthetische Pestizide
sind hier ausgeschlossen. Speziell bei Naturland-Weihnachtsbäumen wurden die Richtlinien für die ökologische Waldnutzung von Naturland
zwischen den Umweltverbänden Robin Wood, Greenpeace und
BUND erarbeitet. Zu den Bio-Kriterien gehört der Verzicht auf Kahlschlag, Pestizide,
Düngungen und Entwässerungsmaßnahmen. Nachhaltige Weihnachtsbäume kommen auch aus FSC-zertifizierten Wäldern.
I blog often and I genuinely thank you for your content. The article has really peaked my interest.
I’m going to bookmark your site and keep checking for new details about once per week.
I subscribed to your RSS feed too.
In some instances, we find ourselves in a junction in life.
On a side would be a more unmanageable quest which can be a little bit more pleasing,
whereas another could possibly be the path of least resistance,
or simply just one more trail. What ever route you’ll go with will most likely determine numerous things for your outcomes in life.
Pediatric massage therapy is definitely the way that I spend nearly all of my working days,
and this is exceedingly fulfilling. Although, I may just as simply have selected something different,
in particular, life as being a clerk or possibly as an ocean scientist.
We will never know how substituting even only one simple thing could possibly transform each and every
piece of our experience. Those are basically considerations to ponder.
I appreciate your providing this information for folks wanting to get more info on subject areas similar to this.
Your blog page was well-written and well researched, and that
is substantially appreciated. I am generally seeking completely new websites to consider and surf regularly. http://Pa.ts.ySla.t.e.r1.213.3@iurii.com/go.php?go=http://Ycantho.com/qa/member.php%3Fu=962926
Excellent blog right here! Also your site lots up very fast!
What web host are you the usage of? Can I am getting your
affiliate link for your host? I wish my site loaded up as
fast as yours lol
Here is my site … สมัคร หวยออนไลน์
For newest news you have to go to see world-wide-web
and on world-wide-web I found this web page as a best website
for hottest updates.
Great post but I was wondering if you could write a litte more on this subject?
I’d be very thankful if you could elaborate a little bit further.
Thank you!
Heya just wanted to give you a brief heads up and let you know a few of the pictures aren’t loading properly.
I’m not sure why but I think its a linking issue. I’ve tried it in two different browsers
and both show the same results.
hi!,I love your writing very a lot! proportion we communicate more about your post
on AOL? I require an expert in this area to solve my problem.
Maybe that’s you! Looking ahead to peer you.
Very nice post. I just stumbled upon your blog and wished to say that I
have truly enjoyed surfing around your blog posts. In any case I’ll be subscribing to your rss feed and I hope you
write again soon!
I used to be suggested this web site by way of my cousin. I am
no longer positive whether or not this submit is written by
way of him as no one else recognise such exact about my difficulty.
You’re amazing! Thanks!
I every time used to read article in news papers but now as I am a user of internet therefore from now I am
using net for content, thanks to web.
Wondeгfuⅼ beаt ! Ӏ would ⅼike to apprentice while you amend yοᥙr sitе, how can i subscribe for a
blogɡ site? The aaccount helped me a acceptable deal. I had been tiny bit acquainted of thi your broadcast offered brght clear cⲟncept
My bⅼoɡ post :: lines
Wow, this post is pleasant, my younger sister is analyzing such things, thus I am going to
inform her.
I’m extremely impressed with your writing skills and also with the layout on your weblog.
Is this a paid theme or did you customize it yourself?
Anyway keep up the excellent quality writing, it
is rare to see a great blog like this one today.
Great blog right here! Also your website loads up fast!
What web host are you the use of? Can I get your affiliate hyperlink in your host?
I wish my site loaded up as fast as yours lol
Howdy! I know this is somewhat off topic but I was
wondering which blog platform are you using for
this website? I’m getting sick and tired of WordPress because I’ve
had issues with hackers and I’m looking at alternatives for
another platform. I would be awesome if you could point me
in the direction of a good platform.
I will immediately clutch your rss as I can not in finding your email subscription hyperlink
or e-newsletter service. Do you have any? Please permit me realize so that
I may subscribe. Thanks.