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
Right now it sounds like WordPress is the top blogging platform available right now.
(from what I’ve read) Is that what you’re using on your blog?
Here is my page :: housefast
If some one wishes expert view about blogging and site-building afterward i advise him/her to go to
see this webpage, Keep up the pleasant job.
Write more, thats all I have to say. Literally, it seems as though you relied on the video to
make your point. You clearly know what youre talking about, why waste your intelligence on just
posting videos to your weblog when you could be giving us something informative to read?
Excellent site you have here but I was wondering if you knew of any discussion boards that cover the same topics
talked about here? I’d really love to be a part of group where I can get opinions from other experienced people that share
the same interest. If you have any recommendations, please let me know.
Many thanks!
you’re truly a excellent webmaster. The web site loading speed
is incredible. It seems that you’re doing any unique trick.
Moreover, The contents are masterpiece. you have
done a excellent job on this subject!
Hi my family member! I wish to say that this article is awesome, great written and include approximately
all important infos. I would like to look extra posts like this .
Good post. I am going through many of these issues as well..
I read this paragraph completely regarding the comparison of most up-to-date and
previous technologies, it’s awesome article.
Hi there! Do you know if they make any plugins to assist with Search
Engine Optimization? I’m trying to get my blog to
rank for some targeted keywords but I’m not seeing very
good results. If you know of any please share. Thank you!
As I web site possessor I believe the content matter here is rattling great , appreciate it for your hard
work. You should keep it up forever! Good Luck.
What’s up to every one, for the reason that I am in fact eager of reading this
weblog’s post to be updated daily. It includes pleasant data.
Great website. A lot of useful info here. I am sending it to some friends ans also
sharing in delicious. And naturally, thanks in your sweat!
important review. Furthermore visit many of our site to learn slot deposit pulsa tanpa potongan. This amazing site
has received excellent reputation right from slot pulsa tanpa potongan wagering associates in Dalam negeri.
At this time there are actually many eye-catching
promos need to anyone previously join presently.
Woah! I’m really digging the template/theme of this blog.
It’s simple, yet effective. A lot of times it’s challenging to get that “perfect balance”
between user friendliness and visual appeal. I must say that you’ve done
a very good job with this. Additionally, the blog loads very
fast for me on Firefox. Exceptional Blog!
When I originally left a comment I seem to have clicked on the -Notify me when new comments are added- checkbox
and now each time a comment is added I receive 4 emails with the same
comment. Is there a way you are able to remove me from that service?
Appreciate it!
Hello There. I found your blog using msn. This is an extremely well written article.
I will be sure to bookmark it and come back to read
more of your useful information. Thanks for the
post. I’ll definitely comeback.
I am genuinely pleased to read this website posts which carries lots of valuable information, thanks for providing these statistics.
Thank you for the good writeup. It in fact was a amusement account it.
Look advanced to far added agreeable from you! By the way, how could we communicate?
We stumbled over here coming from a different web
page and thought I may as well check things out.
I like what I see so i am just following you.
Look forward to looking into your web page repeatedly.
Great delivery. Sound arguments. Keep up the amazing spirit.
Wow, that’s what I was exploring for, what a stuff!
existing here at this blog, thanks admin of this
site.
You are a very smart individual!
Hi there, I would like to subscribe for this web site to obtain most
recent updates, so where can i do it please help.
This is very interesting, You are a very skilled blogger.
I’ve joined your feed and look forward to seeking more of
your magnificent post. Also, I have shared your web site in my social
networks!
Its like you read my mind! You appear to know so much about
this, like you wrote the book in it or something.
I think that you could do with some pics to drive the message home a little bit, but instead of that, this is great blog.
A great read. I’ll definitely be back.
Admiring the dedication you put into your blog and in depth information you provide.
It’s awesome to come across a blog every once
in a while that isn’t the same outdated rehashed material.
Wonderful read! I’ve bookmarked your site and I’m adding your RSS feeds to my
Google account.
If you wish for to grow your experience simply keep visiting this web site and be updated with the most up-to-date information posted here.
Hey are using WordPress for your site platform? I’m new to the blog world but I’m trying to get started and set up my
own. Do you need any html coding expertise to make your own blog?
Any help would be really appreciated!
Piece of writing writing is also a excitement, if you know afterward you can write or else it is difficult to
write.
Zusätzlich bestimmt das Kabel die Reichweite – ist es nicht lang genug,
muss der Staubsauger an einer anderen Steckdose angeschlossen werden. Beim Akkusauger treten diese Probleme des Saugens nicht auf.
Er besteht aus einer verstellbaren Saugstange ohne einen sperrigen Korpus und Kabel.
Treppen stellen jeden Bodensauger vor eine Herausforderung.
In beiden Fällen bietet der Akku-Staubsauger mit leichtem tragbarem Korpus mehr Flexibilität und eine einfachere
Handhabung. Bei kabelgebundenen Staubsaugern ist der Saugschlauch zumeist nicht sehr
lang, sodass höher gelegene Stellen nicht oder nur schwer zu erreichen sind.
Wie gut reinigen Akku-Staubsauger den zu saugenden Bereich?
Die Saugleistung der Akku-Staubsauger wird von den kabelgebundenen Bodenstaubsaugern übertroffen. Akku-Staubsauger haben nicht nur Vorteile gegenüber herkömmlichen Bodenstaubsaugern,
sondern bringen auch Nachteile mit sich, die hier gegenübergestellt werden. Kabelgebundene Staubsauger können beliebig lang auf beliebig starkem
Saug-Modus herhalten müssen, während die Laufzeit des Akkusaugers erst
recht bei hoher Saugstufe stark begrenzt ist.
Viele Akku-Staubsauger halten im stärksten Saug-Modus nur wenige Minuten durch.
Manche Modelle haben eine Laufzeit von nur 10 Minuten, was meist nicht ausreicht, um den gesamten Haushalt zu säubern.