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
Nice answers in return of this issue with genuine arguments and telling all regarding that.
Very good information. Lucky me I recently found your
website by chance (stumbleupon). I have saved it for later!
Does your blog have a contact page? I’m having trouble locating it
but, I’d like to shoot you an email. I’ve got some ideas for your blog you might be
interested in hearing. Either way, great site and I look forward
to seeing it expand over time.
I am actually thankful to the owner of this website who has shared this great paragraph at at this place.
I visited various web sites but the audio quality for audio songs present at this web
page is really wonderful.
Hmm it appears like your website ate my first comment (it was extremely long) so I guess I’ll just sum
it up what I wrote and say, I’m thoroughly enjoying your blog.
I too am an aspiring blog writer but I’m still new to the whole thing.
Do you have any recommendations for inexperienced blog writers?
I’d really appreciate it.
Hello there, just became alert to your blog through Google, and found that it is really
informative. I’m going to watch out for brussels. I’ll be grateful if you
continue this in future. Numerous people will be benefited from your writing.
Cheers!
SEO-Agenturen sind besser beraten, wenn der Vertrag als Dienstvertrag gilt, und sehen dies daher häufig in ihren allgemeinen Geschäftsbedingungen vor.
Denn bei Dienstverträgen gibt es grundsätzlich keine Gewährleistungsansprüche
bei einer „Schlechtleistung”, wie die qualitative Abweichung von der vereinbarten Leistung in der Rechtssprache heißt. In den meisten Fällen sollte dies die SEO-Agentur übernehmen, da sie sich von Haus aus damit besser auskennt als der Auftraggeber. Der SEO-Vertrag sollte überdies klarstellen, dass unzulässige Maßnahmen, auch als Black-Hat-Methoden bezeichnet, nicht umgesetzt werden dürfen. Festzulegen ist auch, wer sich ums Einhalten der jeweiligen Richtlinien der Suchmaschinenbetreiber kümmern und deren Vorgaben umsetzen muss. Unzulässige Methoden sind beispielsweise das automatische Anmelden in Foren, die Übernahme nimmer genutzter Domains, um sich deren Ranking zuzurechnen, der Aufbau eines „Private Blog Network” mit gegenseitigen Verlinkungen (Cross Links) oder das sogenannte Cloaking, bei dem den Suchmaschinencrawlern andere Inhalte angezeigt
werden als den Internetnutzern. Die Bezeichnung „Black Hat” stammt aus Westernfilmen, in denen der Bösewicht meist einen schwarzen Hut trug. Andere Erscheinungsformen der nicht zulässigen Suchmaschinenoptimierung sind das Keyword Stuffing, Keywords als versteckter Content oder duplizierte Inhalte.
Have you ever thought about adding a little bit more than just
your articles? I mean, what you say is important
and everything. However think of if you added some great
visuals or videos to give your posts more, “pop”!
Your content is excellent but with images and video
clips, this site could certainly be one of the most beneficial in its field.
Terrific blog!
Thank you for every other informative website.
Where else could I am getting that kind of info written in such a perfect approach?
I have a challenge that I’m just now operating on, and I’ve been on the look out for such information.
Nice blog! Is your theme custom made or did you download it
from somewhere? A design like yours with a few simple adjustements
would really make my blog shine. Please let me know where you got
your theme. Cheers
Allerdings werden Nordic Walking Stöcke in Längenabständen von 5 cm (selten auch 2,5cm) angeboten, so dass im gegebenen Fall gerundet werden muss.
Dabei angezeigt gerade bei Einsteigern eher abzurunden und einen kürzeren Stock zu wählen.
Als erfahrener Trainer kann man gerade durch (sinnvolle!) Variation der
Stocklänge unterschiedliche Trainingsreize setzen. Fortgeschrittene dynamische Nordic Walker können ruhig auch mit einem größeren Stock arbeiten.
Für Anfänger ist der Winkel sogar noch mehr größer zu wählen, mehr oder weniger Technik einfacher zu
erlernen. Als zweite Möglichkeit (wenn man nicht immer rechnen möchte) geschickt die praktische Lösung: Stock
und Unterarm sollten bei fest umfassten Griff und gerade aufgestelltem Stock einen leicht größeren Winkel als 90° ergeben. Stocklängen trotz gleicher Körpergröße optimal versorgt.
Bei dieser Art der individuellen Stocklängenzuweisung werden auch verschiedene Menschentypen (z.B.
4. Wie viel sollten Nordic Walking Stöcke kosten? Der Preis variiert abhängig von der Qualität
des Schafts, vom Material beziehungsweise dem Carbonanteil als auch vom Schlaufensystem.
Die Preisspanne für einen Qualitätsstock bewegt sich zwischen 40€ und 100€.
Gelegenheitswalker bekommen zwischen 40-50€ das beste Preis-Leistungs-Verhältnis, Walker die ihre Stöcke öfter als 3mal diese Woche im Einsatz
haben, sollten entsprechend tiefer ins Portemonnaie greifen.
If some one needs to be updated with most recent technologies afterward he
must be visit this web site and be up to date daily.
I got this site from my buddy who shared with me concerning this web site and at the moment this time I
am browsing this web page and reading very informative posts at this time.
Do you have a spam problem on this website; I
also am a blogger, and I was curious about your situation; we have created
some nice practices and we are looking to exchange solutions with other
folks, please shoot me an e-mail if interested.
Hey I know this is off topic but I was wondering if you knew of any widgets I could add
to my blog that automatically tweet my newest twitter updates.
I’ve been looking for a plug-in like this for quite some time and was
hoping maybe you would have some experience with something like this.
Please let me know if you run into anything. I truly enjoy reading your blog and I
look forward to your new updates.
Hmm is anyone else having problems with the images on this blog loading?
I’m trying to figure out if its a problem on my end or if it’s the blog.
Any suggestions would be greatly appreciated.
I for all time emailed this blog post page to all my contacts, since if like to read it afterward my contacts will too.
Very nice post. I simply stumbled upon your blog and wanted to say that I have really
loved browsing your blog posts. After all I’ll be subscribing in your rss feed and I hope you write again soon!
I like it when folks get together and share views.
Great site, continue the good work!
Its like you learn my thoughts! You seem to grasp a
lot about this, like you wrote the ebook in it or something.
I feel that you simply can do with some p.c. to power the message home a
little bit, however instead of that, this is wonderful blog.
A great read. I will definitely be back.
This is very interesting, You are a very skilled blogger. I have
joined your rss feed and look forward to seeking more of your great post.
Also, I have shared your web site in my social networks!
Hello are using WordPress for your site platform?
I’m new to the blog world but I’m trying to get started
and create my own. Do you require any html coding expertise
to make your own blog? Any help would be really appreciated!
always i used to read smaller articles or reviews which as well clear their motive,
and that is also happening with this post which I am reading at this place.
Spot on with this write-up, I seriously feel this website
needs much more attention. I’ll probably be back again to see
more, thanks for the info!
Hi mates, fastidious post and pleasant urging commented at this
place, I am genuinely enjoying by these.
Genuinely no matter if someone doesn’t know after that its up to other users that they will
assist, so here it takes place.
I’ve been exploring for a little bit for any high-quality articles
or weblog posts on this sort of house . Exploring in Yahoo I
at last stumbled upon this website. Reading this info
So i’m happy to express that I’ve a very excellent uncanny feeling I came upon exactly what
I needed. I so much undoubtedly will make certain to
don?t fail to remember this website and give it
a glance on a continuing basis.
Hi! I could have sworn I’ve been to this blog before but after browsing through some of
the post I realized it’s new to me. Anyways, I’m definitely happy I
found it and I’ll be bookmarking and checking back
frequently!
Hi there it’s me, I am also visiting this website daily, this site is actually pleasant and the people are genuinely sharing fastidious thoughts.