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
Я одно время думал просто играть в слоты, без бонусов.
Hey would you mind sharing which blog platform you’re working with?
I’m planning to start my own blog soon but I’m having a difficult time selecting
between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and
I’m looking for something completely unique.
P.S Sorry for getting off-topic but I had to ask!
Поначалу еще были сомнения, а теперь уже точно уверен, что других казино мне точно не надо.
Why visitors still use to read news papers when in this technological world everything is available on web?
What’s up i am kavin, its my first time to commenting anywhere, when i read this article
i thought i could also make comment due to this brilliant post.
In our online site, you see fit discover a multitude of distinguishable https://maxikagames.com games across several themes, which ordain not purely provide happiness and help you relieve but also let you to broaden cardinal intellectual and suitable exciting people from for everyone the world.
Guidebook about Copy Luxury Accessories
Explanations for a Demand for Version High-End Bags
Imitation Luxury Baggage Have Risen On Demand DueTo Various Compelling Motives
Price Symbolize Usually A Driving Factor
Exceptional Copies Offer The Allure Of Brand Designers Without The Hefty Cost
Improvements With Creation Represent That These Imitations Commonly Possess Remarkable Comparisons About An Authentics
With Individuals That Admire Fashion Nevertheless Represent Budget-Conscious
Inspired Upscale Bags Present The Appealing Option
Advice With Spotting Legitimacy
Examining Elements Like Emblems Welds And Hardware
Might Facilitate Uncover A Imitation’s Authenticity
Differentiating These Elements With Pictures Of Original Label Bags
Will Expose Multiple
Alternatives InsteadOf Replica Upscale Luggage
Reasonable Designer Substitutes
Represent Accessible Which Present Chic Substitutes Without Sacrificing Upon Greatness
These Items Represent Officially Manufactured From Designers That Present Upscale Fashion At Attainable
5 Killer Quora Answers On Window Doctor Near Me window
doctor near me; Christine,
If you desire to grow your know-how just keep visiting this
web site and be updated with the most recent news update posted here.
Who Is Responsible For The High Limit Slots Budget?
12 Best Ways To Spend Your Money slot features (https://www.google.com.om)
Simply desire to say your article is as astounding.
The clarity in your post is simply spectacular and i can assume you are an expert on this subject.
Fine with your permission let me to grab your feed to keep up to date with forthcoming post.
Thanks a million and please carry on the gratifying work.
Where Will Slot Rewards One Year From What Is Happening
Now? Top slots
I every time emailed this webpage post page to all my
associates, for the reason that if like to read it
then my friends will too.
Also visit my web page; Oscam Server no Freeze
Hi there, I read your blogs like every week.
Your story-telling style is awesome, keep it up!
Hi there to every body, it’s my first visit of this
website; this weblog carries amazing and really fine material for visitors.
Guidebook to Version High-End Bags
Explanations of the Demand in Inspired Designer Purses
Imitation Designer Purses Have Expanded With Trend BecauseOf Several Powerful Causes
Expense Symbolize Usually The Motivating Encouragement
Excellent Copies Give The Attraction From Brand Designers No The Considerable Expense
Breakthroughs With Construction Mean Who Them InspiredVersions Often Have Notable Likenesses With A Genuine
For Persons That Value Fashion Nonetheless Represent Thrifty
Replica Designer Purses Offer The Enticing Choice
Tips For Spotting Legitimacy
Scrutinizing Elements Like Signs Seams Along Parts
Might Help Discover An Replica’s Authenticity
Comparing Those Aspects To Photos From Original Label Handbags
Might Expose Any
AlternativeOptions InPlaceOf Version Designer Luggage
Affordable Designer Substitutes
Be Available Who Provide Stylish Choices Without GivingUp On Excellence
Those Goods Are Legally Constructed By Manufacturers Which Give Premium Style With Accessible
5 Reasons To Be An Online Ignition Lock Repair Near Me
And 5 Reasons Why You Shouldn’t Ignition Repair service
9 Things Your Parents Teach You About Slot Sites slot
sites (Preston)
Your means of explaining all in this post is really pleasant, every one be able to effortlessly know it, Thanks a
lot https://formationmatieresdangereuses.com/les-chariots-elevateurs-quest-ce-que-cest-et-comment-sont-ils-classes/
I would like to thank you for the efforts you’ve put in penning this website.
I am hoping to check out the same high-grade blog posts by you later on as
well. In truth, your creative writing abilities has inspired me to get my own website now 😉
10 Unexpected Online Clothing Sites Uk Tips Lenox Butterfly Meadow Collection
Thanks, this website is really valuable.
https://rybnicki.com/
Howdy this is kinda of off topic but I was wondering if blogs
use WYSIWYG editors or if you have to manually code with HTML.
I’m starting a blog soon but have no coding expertise
so I wanted to get guidance from someone with experience.
Any help would be enormously appreciated!
Great goods from you, man. I’ve understand your stuff previous to and you are
just extremely fantastic. I really like what you have acquired
here, really like what you are stating and the way in which you say it.
You make it enjoyable and you still care for to keep it smart.
I can not wait to read far more from you. This is actually a great site.
For restricted buildings, we can install ducted cooling without any external system.
Expert Advice On Unique Slots From The Age Of Five high RTP slots –
Magdalena –
Have you ever thought about including a little bit more than just your articles?
I mean, what you say is valuable and all. Nevertheless imagine if you added some great visuals or video clips to give your posts more,
“pop”! Your content is excellent but with images and videos, this website could
undeniably be one of the most beneficial in its field. Excellent blog!
Also visit my page :: مبل راحتی
I just could not go away your web site before suggesting
that I extremely loved the standard information a person provide in your
guests? Is gonna be again often in order to
check out new posts
Hello Dear, are you truly visiting this website on a regular basis, if
so then you will without doubt take nice know-how.
See What Saab Key Replacement Near Me Tricks The Celebs Are Making Use Of near me