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
buy cialis pill: cialist.pro – Cialis 20mg price in USA
What You Need To Do On This Leeds Windows glass Replacement leeds
10 Tips To Know About Online Shopping Sites Vimeo.com
Please let me know if you’re looking for a article
author for your site. You have some really good posts and I
feel I would be a good asset. If you ever want
to take some of the load off, I’d absolutely love to
write some material for your blog in exchange for a link back to mine.
Please send me an email if interested. Thank you!
buy Kamagra: kamagra pills – Kamagra 100mg
11 Ways To Completely Revamp Your Saab Key Programming Near Me Saab Ignition Key
Great post. I was checking constantly this explainer video blog and I’m impressed! Very helpful info specially the last part 🙂 I care for such information a lot. I was seeking this certain information for a long time. Thank you and good luck. https://www.Cleansway.Com/business/explainer-video-company-india
Attractive component to content. I just stumbled upon your blog and in accession capital to say that I get in fact enjoyed account your blog posts. Any way I will be subscribing to your augment and even I achievement you get admission to constantly quickly.
https://nudifyai.net/nudify-free/
Buy Tadalafil 10mg: Generic Cialis without a doctor prescription – Buy Cialis online
Since on the internet intercourse online video
chats are nameless, no have to have to fear about remaining found, and most importantly, you will normally come across the best chat for what you
are on the lookout for. Fascinating dating in sexual
intercourse video clip chat is the best location for a new encounter.
Group chat is a spot the place respect and friendliness are extremely important.
Create your individual singles lounge with stay chat
with strangers, where by respect and friendliness are the
hallmarks of a very good time for all. Know that we are masters of intercourse that like to make our customers find
out new absolutely free porn to masturbate to. Make a absolutely free on line true-time and instant are living chat with your on the net friends.
Such a movie chat offers the option to satisfy two or extra
strangers in get to just chat, expose their tricks and make virtual adore.
This is mainly because people have oral micro organism that feed on carbs, and, as
a facet effect, also split down human teeth far more.
My blog post: top webcam sites
Buy Vardenafil 20mg online: Buy Vardenafil 20mg – Levitra 10 mg best price
http://kamagra.win/# sildenafil oral jelly 100mg kamagra
15 Best Pinterest Boards To Pin On All Time About Double Glazed Windows Near Me Double glazing units replacement
viagra without prescription: Buy Viagra online cheap – sildenafil over the counter
hello there and thank you for your information on explainer Videos ? I?ve certainly picked up something new from right here. I did however expertise several technical points using this website, as I experienced to reload the website many 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 could damage your high-quality score if ads and marketing with Adwords. Anyway I?m adding this RSS to my email and could look out for much more of your respective fascinating content. Ensure that you update this again very soon.. https://www.Adlocalpages.Com/business-professional-services/explainer-video-company-india
What’s The Current Job Market For Windows Luton Professionals Like?
windows Luton
Highly energetic article, I loved that bit. Will there be a part
2?
8 Tips To Increase Your Truck Accident Lawyer Game
hempstead truck accident lawyer
Ask Me Anything: 10 Answers To Your Questions About Defra
Approved Back+Boiler Stoves DEFRA Stoves Ratings
It is explainer video company india appropriate time to make some plans for the expaliner videos and it is time to be happy. I’ve read this post and if I could I want to suggest you few interesting things or advice. Perhaps you could write next articles referring to this article. I desire to read more things about it! https://www.Classifiedads.Com/home_services_stores/7fx3nlvdk3db4
15 Terms That Everyone Is In The Upvc Windows Repair Industry Should Know Upvc Repairs
cheap kamagra: kamagra.win – Kamagra 100mg price
It’s explainer video company india the best time to make some plans for the expaliner videos and it’s time to be happy. I have read this post and if I could I desire to suggest you some interesting things or advice. Maybe you could write next articles referring to this article. I wish to read more things about it! https://99designs.Dk/profiles/8076816/about
I don’t know if it’s just me or if perhaps everybody
else encountering issues with your website. It appears as if some of the text on your content are running off
the screen. Can somebody else please comment and let me know if
this is happening to them as well? This could be a issue with my internet browser because I’ve had this happen previously.
Cheers
20 Misconceptions About Ghost 2 Immobiliser Fitting Near Me:
Busted ghost 2 immobiliser fitting near me
cheap kamagra: kamagra oral jelly – buy kamagra online usa
I was pretty pleased to uncover this website. I wanted to thank you for ones time for
this wonderful read!! I definitely loved every bit of it and I have you saved as a
favorite to look at new stuff in your web site.
Hey There. I discovered your blog the usage of msn. That is a very smartly written article.
I will make sure to bookmark it and return to learn more
of your useful information. Thank you for the post. I will certainly comeback.
https://levitrav.store/# Buy Vardenafil online
https://levitrav.store/# Buy generic Levitra online