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
вывод из запоя воронеж http://superogorod.ucoz.org/forum/2-2086-1/ .
Купить дженерики с доставкой по Санкт-Петербургу качественные препараты для повышения потенции
на сайте https://men78.ru высокое качество производства Индии в наличии в СПБ
выведение из запоя воронеж стационар https://stranaua.ukrbb.net/viewtopic.php?f=2&t=59768 .
This design is incredible! You obviously know how to keep a reader entertained.
Between your wit and your videos, I was almost moved to start my own blog (well, almost…HaHa!) Excellent job.
I really loved what you had to say, and more than that, how you presented it.
Too cool!
лечение наркозависимости в стационаре gaslo.ukrbb.net/viewtopic.php?f=13&t=3413 .
выведение из запоя воронеж стационар https://www.family2.quadrobb.me/viewtopic.php?id=1841 .
darknet market dark market link deep web links
вывод из запоя в воронеже http://www.superogorod.ucoz.org/forum/2-2086-1/ .
выведение из запоя воронеж стационар https://planeta.mybb.social/viewtopic.php?id=2229/ .
can i buy clomid for sale: clomid purchase online rex pharm – how to get cheap clomid online
Как не попасть впросак при покупке диплома колледжа или ПТУ в России
cytotec online: cyt premium – buy cytotec online
Как официально приобрести аттестат 11 класса с минимальными затратами времени
I don’t know if it’s just me or if perhaps everyone else
experiencing problems with your blog. It appears like some of the text within your posts
are running off the screen. Can somebody else please comment and let me know if this
is happening to them as well? This may be a issue with my web browser because I’ve had this happen previously.
Thank you
where to buy clomid without dr prescription: buy clomid – can i purchase generic clomid without dr prescription
It’s really very complicated in this full of activity life to listen news on Television, so I
simply use the web for that reason, and take the most up-to-date news.
Check out my website; highstakes Games
вывод из запоя стационар http://www.superjackson.ukrbb.net/viewtopic.php?f=28&t=9734 .
выведение из запоя воронеж стационар justforum.bestforums.org/viewtopic.php?f=26&t=4753 .
вывод из запоя в стационаре воронежа http://www.gaslo.ukrbb.net/viewtopic.php?f=13&t=3413/ .
Thanks for finally writing about > JS 依照元素出現數量排序 – 馬老師 雲端研究室 < Loved it!
вывод из запоя в воронеже gaslo.ukrbb.net/viewtopic.php?f=13&t=3413 .
How do I find the best deals on tours in Dubai? Recommendations for a trusted dhow cruise dubai marina offers would be
There are various tools and websites that affirmation to allow users
to view private instagram viewer without human verification Instagram profiles,
but it’s important to approach these taking into consideration caution. Many of these tools can be unreliable, may
require personal information, or could violate Instagram’s terms of service.
Additionally, using such tools can compromise your own security or
guide to scams. The safest and most ethical way to view a private profile is to send a follow demand directly to the
user. Always prioritize privacy and glorification in your online interactions.
вывод из запоя воронеж http://zarabotokdoma.creartuforo.com/viewtopic.php?id=11483 .
That is really attention-grabbing, You are an excessively skilled blogger.
I’ve joined your rss feed and look forward to in search
of extra of your fantastic post. Additionally, I’ve
shared your site in my social networks
Покупка школьного аттестата с упрощенной программой: что важно знать
60 mg prednisone daily: prednisone 4 mg daily – prednisone pack
These drawbacks are all limited.
Concluded Reading a Blog Post: A Formal Reply to
the Comment Section and an Invitation to Join “KING855”
‘After thoroughly perusing the blog post, I would like to submit the
following feedback to the discussion .
Your perspectives regarding the theme were quite intriguing .
I was in agreement with a number of the claims
you articulated.
It is gratifying to witness such an stimulating dialogue taking place
.
If you are interested in additional investigating
this subject matter , I would sincerely encourage you to become a member of the “KING855” network .
There , you will have the chance to engage with kindred spirit
participants and dive deeper into these intriguing topics
.
I am confident your contribution would be a meaningful
addition to the dialogue.
Appreciate your input , and I anticipate the prospect of extending this stimulating conversation.
Also visit my web site: online casino software providers, Winifred,