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
Begin By Meeting The Steve Jobs Of The Uk Women’s Online Shopping Websites Industry Vimeo
10 Tips For Quickly Getting Window Repair Near upvc window repair Near me
Overview on Inspired High-End Accessories
Reasons behind the Trend in Imitation Designer Handbags
Inspired Luxury Handbags Have Grown In Demand For Many Compelling Factors
Cost Is Often A Driving Encouragement
Exceptional Copies Provide A Allure Of Brand Brands No A Hefty Expense
Improvements On Construction Symbolize Who Those InspiredVersions Often Hold Remarkable Likenesses About The Genuine
For Persons That Value Design However Represent Frugal
Inspired High-End Luggage Present An Alluring Choice
Guidelines With Discovering Validity
Examining Elements Like Signs Stitching Along Components
Might Assist Decide A Imitation’s Reality
Contrasting Those Details Against Graphics From Real Label Bags
Could Reveal Numerous
Alternative InPlaceOf Inspired Upscale Handbags
Affordable Brand Substitutes
Be Accessible Which Offer Chic Substitutes WithNo Sacrificing On Greatness
Them Products Are Formally Constructed By Labels Who Offer High-End Fashion With Reasonable
Truly when someone doesn’t know afterward its up to other visitors
that they will assist, so here it happens.
Admiring the hard work you put into your site and in depth information you offer.
It’s nice to come across a blog every once in a while
that isn’t the same outdated rehashed material. Excellent read!
I’ve saved your site and I’m adding your RSS feeds to my Google account.
The 10 Most Terrifying Things About Slot Promotions Slot promotions
I have read a few good stuff here. Certainly value bookmarking for revisiting.
I wonder how so much effort you set to make the sort of
great informative site.
Today, I went to the beachfront with my children. I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed. There was a hermit crab inside and it pinched her ear. She never wants to go back! LoL I know this is totally off topic but I had to tell someone!
I’m curious to find out what blog system you’re working with?
I’m having some minor security problems with my latest website and I’d like to find something more safeguarded.
Do you have any suggestions?
Don’t Forget Repairs To Double Glazed Windows:
10 Reasons Why You No Longer Need It Window Repairs
How To Know If You’re Ready To Workers Compensation Settlement Workers’ Compensation
You’ll Never Guess This Progressive Jackpot Slots’s
Secrets progressive jackpot slots
no download online casino http://casinowild24.com/casino-reviews/no-download-casinos/ .
Drugs prescribing information. Long-Term Effects.
how can i get zanaflex prices
Actual about medicines. Get information now.
Its History Of Shopping Online Sunbrella Navy Blue Market Umbrella
10 Misconceptions Your Boss Holds Regarding Best Slot Payouts
Popular Slots
You’ll Be Unable To Guess 2 In 1 Highchair’s Benefits 2 In 1 highchair
Introduction on Imitation High-End Baggage
Factors for a Fame for Version Upscale Handbags
Imitation Upscale Handbags Have Grown In Trend BecauseOf Various Convincing Factors
Expense Symbolize Regularly A Driving Encouragement
Outstanding Versions Give The Enticement About Label Designers No A Substantial Expense
Advances With Construction Represent Who These Copies Frequently Hold Remarkable Likenesses To An Originals
To Persons That Enjoy Fashion Nonetheless Represent Economical
Version Designer Baggage Give The Alluring Choice
Suggestions For Spotting Legitimacy
Scrutinizing Details Including Emblems Seams With Hardware
May Facilitate Discover An Version’s Authenticity
Contrasting Those Details To Graphics Of Authentic Designer Handbags
Could Show Some
Alternatives InsteadOf Inspired Designer Handbags
BudgetFriendly Designer Alternatives
Be Available Which Give Chic Options No Compromising On Superiority
These Commodities Represent Authentically Constructed With Designers That Give Luxury Design With Affordable
Каждый год в середине сентября проводится Тюменский инновационный форум «НЕФТЬГАЗТЭК».
Форум посвящен устройству мнтодов инновационного продвижения областей топливно-энергетического комплекса, рассмотрению и определению ответов, организации благоприятных обстоятельств для развития инноваторских проектов. Ежегодный тюменский форум является авторитетной дискуссионной площадкой по развитию нефтегазовой сферы в Российской Федерации, содержит высокий статус и своевременность, созвучен общей стратегии продвижения инноваторского курса в России
-https://neftgaztek.ru/
prescription drugs without the prescription
Overwhelmed by how to start the recovery of your QIWI wallet funds?
Our support team is ready around the clock to
guide you through the process and answer any queries you have.
Choosing our company, you’re selecting a reliable helper in reclaiming your assets.
My partner and I absolutely love your blog and find the majority of your post’s to be just what I’m looking for.
Do you offer guest writers to write content to
suit your needs? I wouldn’t mind producing a post or elaborating on some of the subjects you write in relation to here.
Again, awesome web site!
Lawinplay – You can Use GCash to play in anytime
Free Spins 1000+ Free Demo Slot
Openning Bonus 120% piso back
Searching lawinplay888 on Google or Bing to get free coins
https://lawinplayvip.com/
15 Gifts For The Central Locking Repairs Near Me Lover In Your Life Car door Lock repair Cost Uk
Guide To Fela Case Settlements: The Intermediate Guide In Fela Case Settlements Fela Case Settlements
Тьфу ты, туфта!
eventually, the combination of a modern variant of the super-popular Tamagotchi game with confident tokenomics creates optimistic opportunities for playdoge, the http://www.play-doge.com, not saying already about his attractiveness as a meme coin.
It Is The History Of CS GO Case Battles cases (https://bookmarkingworld.review/story.php?title=10-tips-for-best-case-opening-site-csgo-that-are-unexpected)
You’ll Be Unable To Guess London Online Clothing Shopping Sites’s Tricks London Online Clothing Shopping Sites
The 10 Most Terrifying Things About Demo Slot Sugar demo Slot sugar
(125.141.133.9)
Its like you learn my thoughts! You appear to know so much approximately this,
like you wrote the ebook in it or something. I believe that you simply could do with a few p.c.
to drive the message home a little bit, but instead of
that, this is excellent blog. An excellent read. I’ll definitely be back.