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
generic plavix: Clopidogrel Best Prices – cheap plavix antiplatelet drug
cheapest Lisinopril: Lisinopril 1st – lisinopril price 10 mg
Быстрая схема покупки диплома старого образца: что важно знать?
gamesmaker.ru/forum/common/offtopics/#replyform
dark web sites darknet drug market darkmarket url
Live Music 광주휴게텔
id=”firstHeading” class=”firstHeading mw-first-heading”>Search results
Helρ
Engkish
Tools
Tools
mоvе to sidegar hide
Actions
Ԍeneral
my site ร้านดอกไม้ด่วน
The 2020 yr was hit quite exhausting by the worldwide pandemic Covid-19 and touring all around the world was restricted.
Can’t help but feel inspired seeing locals connect deeply around traditional practices; grateful always having guidance available dubai city tour
Useful information. Fortunate me I found your site by chance, and I’m surprised why this coincidence didn’t happened in advance!
I bookmarked it.
Exclusive Nightlife 밤문화
Happy Hour 부산달리기
Lisinopril 1st: cheapest Lisinopril – zestoretic 20
buy prednisone online uk: how much is prednisone 5mg – prednisone 10mg buy online
Парадокс, но купить диплом кандидата наук оказалось не так и сложно
Have you ever thought about adding a little bit more than just your articles?
I mean, what you say is fundamental and everything. Nevertheless just imagine
if you added some great pictures or videos to give your posts more,
“pop”! Your content is excellent but with pics and videos, this blog could undeniably
be one of the best in its field. Terrific blog!
Casino Blackjack Tips 다바오4989
Аттестат 11 класса купить официально с упрощенным обучением в Москве
Аттестат 11 класса купить официально с упрощенным обучением в Москве
Your method of describing the whole thing in this article is really pleasant, every one can simply be aware of it, Thanks a lot https://www.cabanoneco.ca/
Howdy, i read your blog from time to time and i
own a similar one and i was just curious if you get a lot of spam comments?
If so how do you stop it, any plugin or anything you can recommend?
I get so much lately it’s driving me crazy so any assistance is very
much appreciated.
Hi just wanted to give you a brief heads up and let you know a few of
the images aren’t loading properly. I’m not sure why
but I think its a linking issue. I’ve tried it in two different
web browsers and both show the same results.
I think what you said made a great deal of sense.
But, what about this? what if you wrote a catchier post title?
I am not suggesting your content is not good, but what if
you added a post title that grabbed a person’s attention? I mean JS
依照元素出現數量排序 – 馬老師 雲端研究室
is a little vanilla. You ought to glance at Yahoo’s
front page and watch how they create post titles to get viewers interested.
You might try adding a video or a picture or two to get
readers interested about what you’ve written. In my opinion, it might make your blog
a little bit more interesting.
http://lisinopril1st.com/# buy Lisinopril 1st
Pretty nice post. I simply stumbled upon your blog and
wanted to say that I have really enjoyed surfing around your weblog posts.
In any case I will be subscribing on your rss feed and I’m hoping you write once more soon!
Приветствую. Подскажите, где найтиполезные блоги о недвижимости? Сейчас читаю – https://teplodom78.ru
I love how easy it is to book with P&J Cleaners cleaning service vancouver bc
Plavix generic price PlavixClo Best Price buy plavix
Вы можете купить справки в Москве в нашей клинике https://aleksandriya-med.ru/.
obviously like your web site but you have to check the
spelling on quite a few of your posts. Several of them are rife with spelling problems and I find it very bothersome
to tell the truth on the other hand I’ll certainly come again again.
Just wish to say your article is as astounding. The clearness to your post is
just nice and i could think you are knowledgeable in this subject.
Well with your permission let me to clutch your feed to stay updated with forthcoming post.
Thanks a million and please keep up the gratifying work.