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
Heya i am for the primary time here. I came across this board and I to find It truly helpful & it helped me out a lot.
I’m hoping to provide one thing back and help others
such as you aided me.
Does your website have a contact page? I’m having a tough time
locating it but, I’d like to send you an e-mail. I’ve got some ideas for your blog
you might be interested in hearing. Either way, great website and I look forward to seeing it develop over time.
My family always say that I am killing my time here at net, however I know I am getting
experience all the time by reading thes pleasant posts.
Every weekend i used to go to see this site, because i want enjoyment, for the
reason that this this website conations really nice funny material too.
This blog was… how do you say it? Relevant!!
Finally I’ve found something which helped me. Thanks!
It’s perfect time to make some plans for the longer term and it’s
time to be happy. I have learn this submit and if I may I wish to counsel you few interesting things or advice.
Perhaps you can write subsequent articles relating
to this article. I desire to read more issues approximately it!
Mehrscheiben-Isolierglas (MIG), auch als Wärmedämmverglasung
oder Isolierverglasung bezeichnet, ist ein aus wenige Glasscheiben zusammengesetztes Bauelement für Fenster et alia Verglasungen. Zwischen den Scheiben befindet sich ein Hohlraum, der gas- und feuchtigkeitsdicht verschlossen ist und der Schall- und Wärmedämmung dient.
In den ersten Jahrzehnten seit Aufkommen von Mehrscheiben-Isolierglas (1950er bis
1970er Jahre) hatte die Marke Thermopane im deutschen Sprachraum
eine große Verbreitung. Vorläufer waren die Doppelverglasung ohne Luftabschluss, das Verbundfenster und die doppelte Einzelverglasung beim Kasten- oder beim Winterfenster.
Der Name wurde zeitweilig zum Synonym für Zweischeiben-Isolierglas.
Als Produktbezeichnung werden auch die Ausdrücke Klimaschutzglas, Thermoglas, Wärmedämmglas oder Wärmeschutzglas verwendet.
Ausdrücke wie Sonnenschutzglas, Sichtschutzglas, Einbruchschutzglas oder Schallschutzglas
bezeichnen in der Summe ein Mehrscheiben-Isolierglas mit speziellen zusätzlichen Eigenschaften, wiewohl eine einzelne
Flachglaskonstruktion diese ebenfalls haben kann.
Im Unterschied zu wärmeren Klimazonen steht in Zentral- und Nordeuropa bei wärmedämmenden Fenstern weniger die Reduzierung der erforderlichen Kühlungsenergie (hohe Betriebskosten von Klimaanlagen), als vielmehr eine wesentliche Einsparung
bei der Heizenergie für Gebäude im Vordergrund.
What’s up, this weekend is pleasant in support of me, because this occasion i am
reading this great educational paragraph here
at my house.
Hi there, for all time i used to check blog posts here early in the dawn, since i love to find out more and more.
I am extremely impressed along with your writing abilities and
also with the structure to your blog. Is that this a paid subject matter or did you customize it your self?
Either way stay up the excellent quality writing, it’s rare to see a great weblog like this
one nowadays..
I’m not that much of a internet reader to be honest but your blogs really nice, keep
it up! I’ll go ahead and bookmark your website to come back later.
Many thanks
Hmm is anyone else having problems with the images on this blog
loading? I’m trying to find out if its a problem on my end or if it’s the blog.
Any feedback would be greatly appreciated.
hello there and thank you for your information – I have
certainly picked up something new from right here.
I did however expertise some technical points using this website, as I experienced to
reload the web site lots of times previous to I could get it to load correctly.
I had been wondering if your web hosting is OK? Not that I’m
complaining, but slow loading instances
times will very frequently affect your placement in google and can damage your quality score if ads
and marketing with Adwords. Well I am adding this RSS to my e-mail and could look out for
a lot more of your respective interesting content.
Make sure you update this again very soon.
If some one needs expert view about running a blog afterward i
advise him/her to pay a quick visit this web site, Keep up the nice work.
Yeah bookmaking this wasn’t a bad decision outstanding post!
Zudem sei die Akkureichweite mit nur 83 Minuten deutlich
schlechter und der Preis hoch. Immerhin durch seine starke Saugleistung, die vielen Sensoren und die Qualität konnte der Marken Saugroboter punkten. Da Vorwerk Kobold VR300 direkt
vom Hersteller vertrieben wird, liegen uns dazu keine Kundenbewertungen unabhängiger Onlineshops vor.
Vorwerk Kobold VR300 Saugroboter erhalten Sie exklusiv
im Vorwerk-Onlineshop. Was ist ein Saugroboter? Es gibt mehr Modelle sind flach genug gebaut,
um auch unter niedrige Möbel saugen zu können. Produziert
werden die Saugroboter europäisch a fortiori von bekannten Haushaltsgeräteherstellern, wie Vorwerk
oder Dyson. Staubsaugerroboter sind intelligente, meist
runde Haushaltsgeräte mit einem Durchmesser von durchschnittlich 30 Zentimetern. In den USA, England und Asien kommen die Geräte
dagegen eher von Herstellern, die innerhalb
der Robotertechnologie zuhause sind, wie die iRobot Modelle oder Saugroboter von Xiaomi bzw.
Roborock. Letztere eignen sich extra für Nutzer ohne große
Wohnung, da ihr Zick-Zack-Modus auf großen Flächen unglaublich viel Energie verbraucht.
Im Handel sind Staubsaugerroboter mit Cloud-Anbindung
und intelligenter Laser Navigation, mit Kamera und AI oder
ohne WLAN mit Zufallsnavigation erhältlich. Wie funktioniert ein Saugroboter?
Saugroboter arbeiten ungeheuer viele auf die eines Teppichreinigers und nutzen dazu mehrere rotierende Bürsten bzw.
Walzen, die mit Gummilippen versehen sind.
Howdy! Do you know if they make any plugins to safeguard against hackers?
I’m kinda paranoid about losing everything I’ve worked
hard on. Any recommendations?
This design is wicked! You obviously know how to keep a reader entertained.
Between your wit and you videos, I was almost moved to start
my owwn blog (well, almost…HaHa!) Excellent job.
I really loved what you hhad tto say, andd more than that,
howw you presented it. Too cool!
Feel freee to visit my blog 온라인바카라
If you wish for to take a great deal from this article then you have to
apply these strategies to your won webpage.
Piece of writing writing is also a fun, if you be familiar with after that you can write otherwise it is difficult to write.
Hi, all is going nicely here and ofcourse every one is sharing data,
that’s really good, keep up writing.
With havin so much content and articles do you ever run into any issues of plagorism
or copyright infringement? My website has a lot of unique content I’ve
either created myself or outsourced but it looks
like a lot of it is popping it up all over the internet without
my authorization. Do you know any techniques to help stop content from being ripped off?
I’d definitely appreciate it.
Utterly indited articles, thank you for information.
Ahaa, its pleasant discussion concerning this
article here at this webpage, I have read all that, so now me also commenting here.
Hi there everyone, it’s my first pay a visit at this site,
and piece of writing is really fruitful for me, keep up posting such articles or
reviews.
If some one wants expert view concerning running a blog afterward
i suggest him/her to pay a quick visit this blog, Keep up the
nice job.
When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get several emails with the
same comment. Is there any way you can remove people from that service?
Thanks!
I visited many web sites but the audio quality for audio songs current at this site is actually excellent.
What i don’t realize is in truth how you’re now not really much more
well-favored than you may be now. You are so intelligent.
You recognize thus considerably on the subject of this matter, made me for
my part believe it from numerous numerous angles. Its like women and men don’t seem to be interested unless it is one
thing to do with Lady gaga! Your own stuffs outstanding. Always take care of it up!
Great delivery. Solid arguments. Keep up the great effort.