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
네이버 아이디 판매
네이버 아이디 판매. 네이버 아이디 구매. 네이버아이디매입. 네이버 아이디 판매 가격. 네이버 실명 아이디 구매.
Hello, I want to subscribe for this web site to take newest updates, therefore where can i do it please help.
It’s an remarkable paragraph in support of all the
web users; they will take benefit from it I am sure.
15 Up-And-Coming Slot Volatility Bloggers You Need To See Online Slots Real Money
12 Facts About Tier Link Building To Make You Think Twice About
The Cooler Water Cooler tier 2 link building (http://wiki.Gptel.ru/)
Tego typu podejrzana aplikacja wydaje sie byc oprogramowaniem
do pobierania filmow online, jednakze wielu uzytkownikow zgodnie twierdzi ze program w
ogole nie dziala.
Slot Demo Princess Terbaru Tools To Ease Your Daily Lifethe One Slot Demo Princess Terbaru
Trick Every Person Should Be Able To Slot demo princess terbaru (wiki.team-glisto.Com)
You’ll Never Guess This Window Seal Replacement’s Tricks Window seal replacement
The Most Effective Reasons For People To Succeed At The Online Shop Industry
Ergonomic L Shaped Desk With Storage
Have you ever thought about writing an e-book or guest authoring on other
sites? I have a blog based on the same ideas you discuss and would really like to have
you share some stories/information. I know my subscribers
would enjoy your work. If you are even remotely interested, feel free
to send me an e-mail.
Hi there it’s me, I am also visiting this site on a
regular basis, this web site is actually nice and the users
are genuinely sharing fastidious thoughts.
Pills information sheet. What side effects can this medication cause?
where buy cheap tetracycline
All news about medicine. Read now.
Hello, I enjoy reading all of your article.
I like to write a little comment to support you.
Undeniable Proof That You Need High Variance
Slots Low variance Slots
Upvc Windows Near Me Tools To Streamline Your Daily Life Upvc Windows Near Me Technique Every Person Needs To Be Able To upvc
windows near me [dudoser.Com]
hi!,I like your writing so a lot! proportion we be
in contact extra approximately your article on AOL?
I need an expert on this space to unravel my problem.
May be that is you! Having a look forward to peer you.
Thank you for the auspicious writeup. It in fact was a amusement account it.
Look advanced to far added agreeable from you!
However, how can we communicate?
My blog; double bed and mattress
Cheers! Useful stuff!
Актуально. Скажите мне, пожалуйста – где я могу найти больше информации по этому вопросу?
4592 of those cryptocurrencies. 0.030031. waffles is registered on one exchange with single number of active https://wafflestoken.com/ on one market.
Where Can You Find The Top Slot Demo Gratis Information? akun Demo princes
The 12 Most Popular Slot Rankings Accounts To Follow On Twitter Best Slots
Overview on Imitation Designer Luggage
Reasons for an Demand of Version Designer Handbags
Inspired Upscale Purses Hold Grown On Popularity BecauseOf Various Convincing Motives
Expense Represent Frequently An Influencing Motivation
Superb Versions Present An Allure Of Brand Brands No The High Cost
Improvements In Manufacturing Mean That These InspiredVersions Usually Have Notable Likenesses With The Real
With Those That Enjoy Style Nonetheless Are Budget-Conscious
Copy Luxury Bags Supply A Inviting Choice
Tips With Recognizing Validity
Analyzing Features Including Icons Joints Plus Accessories
Can Help Uncover An Version’s Reality
Comparing Those Features Against Graphics About Actual Label Accessories
Will Expose Several
Alternatives InPlaceOf Copy Luxury Purses
AffordablyPriced Designer Replacements
Represent Available Which Provide Vogue Alternatives Without GivingUp With Greatness
Those Goods Be Officially Created By Brands That Offer Premium Design For Attainable
When I initially commented I clicked the “Notify me when new comments are added” checkbox and
now each time a comment is added I get four emails with the same comment.
Is there any way you can remove me from that service?
Thank you!
See What Can I Buy From A Uk Website Tricks The Celebs Are Making Use
Of can i buy from a uk website (koreasamsong.com)
Please let me know if you’re looking for a article author for your site.
You have some really great articles and I think I would be a good asset.
If you ever want to take some of the load off, I’d absolutely love to write
some articles for your blog in exchange for a link back to mine.
Please shoot me an e-mail if interested. Regards!
Appreciating the hard work you put into your site and detailed information you provide.
It’s awesome to come across a blog every once in a while that isn’t the same outdated
rehashed material. Fantastic read! I’ve saved your site
and I’m including your RSS feeds to my Google account.
20 Inspirational Quotes About Slot Demo 20 slot demo gratis maxwin (https://www.simong.co.kr/main/bbs/board.php?bo_table=free&wr_id=69984)
For newest news you have to pay a quick visit web and on web I found
this site as a most excellent web site for hottest updates.
The 9 Things Your Parents Teach You About Local SEO Services Uk local Seo Services
uk [jahc.inckorea.net]
This text is worth everyone’s attention. How can I find out more?