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
12 Facts About Double Glazed Window Suppliers Near Me
That Will Make You Look Smart Around The Cooler Water
Cooler double glazing quotes (Orville)
Today, I went to the beach front with my kids. 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 put 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 entirely off topic but I had to
tell someone!
Is Your Company Responsible For A Cheap Online Shopping Sites Uk Budget?
Twelve Top Ways To Spend Your Money 100% recycled towels
Roseline is what’s written on her birth certificate and she totally
loves this full name. North Carolina may be the place
Enjoy most which enables it to never idea. One
of factors that she loves most is bottle tops collecting an excellent she is hoping to cash with it.
Interviewing is how I make money.
Drugs prescribing information. Long-Term Effects.
where to buy generic elavil tablets
All what you want to know about drugs. Read information here.
This Story Behind London Online Mobile Shopping Sites Will Haunt You For The Rest Of Your Life!
vimeo.Com
The Ultimate Glossary Of Terms About Fela Settlements fela railroad
15 Shocking Facts About Certified Slots Bonus round slots
This Week’s Most Remarkable Stories About Slot Strategies Slot Strategies slots with free Bonus rounds
לנעימה במיוחד. בשביל סוג זה של בילויים עם נערות ליווי בעפולה אי אפשר אחרת. 2. פרטיות ודיסקרטיות – רוב האנשים אשר מבלים הפרטיות אנחנו לא מציעים «סתם» דירות דיסקרטיות בצפון. חשוב לנו לספק לך פרטיות מלאה במקומות בילוי בהם תוכל להיפגש עם כל בחורה נערות ליווי בחיפה
Asking questions are truly fastidious thing if you are not understanding something completely, except this post provides fastidious
understanding yet.
Introduction about Copy Luxury Purses
Factors for the Fame in Copy Premium Bags
Replica Designer Handbags Have Risen On Popularity DueTo Several Compelling Reasons
Cost Represent Regularly An Driving Encouragement
Superb Versions Supply An Appeal From Designer Labels WithNo A Expensive Cost
Advancements In Manufacturing Mean Who Them InspiredVersions Usually Hold Remarkable Comparisons To A Originals
With People Who Value Mode But Be Thrifty
Inspired Luxury Baggage Give A Alluring Replacement
Guidelines For Detecting Genuineness
Scrutinizing Details Including Signs Stitching Along Components
Could Facilitate Uncover A Replica’s Authenticity
Matching Them Aspects Against Pictures Of Real Label Handbags
Will Expose Any
Alternatives To Replica Designer Luggage
AffordablyPriced Brand Substitutes
Be Accessible Who Offer Trendy Options WithNo Sacrificing With High Standards
Those Products Be Legally Produced From Designers That Give Luxury Design With Attainable
What Experts On All CSGO Skins Want You To Know Gamma 2 case
Is Double Glazed Units Near Me The Most Effective Thing That
Ever Was? Replacement double Glazed units Near me
Online Shopping Websites Clothes Tools To Improve
Your Daily Lifethe One Online Shopping Websites Clothes Trick Every Person Should Be Able To Online Shopping Websites Clothes
20 Resources That Will Make You Better At Certified
Slots Top Jackpot Slots
The Most Innovative Things Happening With Content Marketing Agencies Uk content marketing agency
I was able to find good advice from your content.
10 Life Lessons We Can Learn From Online Shopping Websites List Aquarium Ammonia Remover
11 Ways To Completely Revamp Your Online Home Shop Uk Discount Code Home Workout Essentials
20 Things You Must Know About Double Glazed Near Me
double Galzed Windows
A Step-By-Step Instruction For Double Glazed Near Me Double Glaze Door
Hi there, just became aware of your blog through Google, and found that it’s
truly informative. I am going to watch out
for brussels. I will be grateful if you continue this in future.
Lots of people will be benefited from your writing.
Cheers!
That is a really good tip especially to those new to the blogosphere.
Brief but very accurate information… Many thanks for sharing this one.
A must read post!
Na esfera “Todo mundo os Exames”, apresentamos certa
compilação amplo de exames com biologia molecular destinados especificamente
aos médicos veterinários.
My blog: Homepage [https://Coolpot.Stream/]
Guidebook about Copy Premium Purses
Reasons behind a Popularity for Imitation Upscale Baggage
Imitation Upscale Handbags Have Risen With Demand BecauseOf Multiple Compelling Factors
Price Represent Usually The Motivating Encouragement
High-Quality Copies Present A Enticement From Label Brands Without An Hefty Cost
Advancements With Creation Symbolize That These InspiredVersions Regularly Hold Remarkable Likenesses To An Real
With People Who Esteem Style Nonetheless Be Frugal
Version High-End Baggage Give A Enticing Choice
Advice To Detecting Authenticity
Analyzing Features SuchAs Logos Welds Along Parts
Will Facilitate FigureOut A Imitation’s Legitimacy
Comparing Those Characteristics Against Pictures From Genuine Label Bags
May Highlight Any
AlternativeOptions InPlaceOf Copy Luxury Bags
Accessible Brand Replacements
Represent Achievable Which Supply Chic Alternatives WithNo Sacrificing Upon Excellence
These Goods Are Officially Created By Brands Which Present Upscale Vogue At Accessible
You’ll Never Be Able To Figure Out This Replacement Upvc Door Panels’s Benefits Replacement upvc door panel
Thanks for sharing your thoughts on caluanie muelear oxidize
производитель. Regards
Five Things Everybody Gets Wrong Regarding GSA SER
Search Engine Ranker gsaser
The 10 Most Terrifying Things About Window Glass Replacement Window Glass Replacement