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
Вордстат используют для сбора
семантического ядра, т. е.
Here is my site; seo продвижение англоязычного сайта
5 Killer Quora Answers To Demo Slot Gatot Kaca Fury demo slot gatot kaca fury
Medicament information sheet. Cautions.
can you buy cheap nolvadex
All information about drugs. Read information now.
20 Fun Facts About Cheap Online Electronics Shopping Uk Under Desk Cpu Mount
Hi there, just became aware of your blog through Google, and found that it is really
informative. I am going to watch out for brussels.
I will appreciate if you continue this in future.
Lots of people will be benefited from your writing. Cheers!
Here is my homepage: fitspresso where to buy
You’ll Never Be Able To Figure Out This Fela
Federal Employers Liability Act’s Benefits Fela federal employers Liability act
After exploring a handful of the blog posts on your web page,
I seriously like your way of writing a blog. I added it to my bookmark webpage list and will
be checking back in the near future. Please visit my web site too and
tell me your opinion.
A Good Rant About Upvc Windows And Doors Near Me replace lock in upvc
door – Bailey –
The Top Reasons Why People Succeed In The Are All Honda Civic Keys The Same Industry honda civic car key
replacement (Garry)
שאתם כל כך רוצים או אפילו כל כך צריכים. אם אינכם רוצים להגיע למכוני העיסוי עדיין תועלו ליהנות ולקבל עיסוי אירוטי במרכז. תמיד דירות דיסקרטיות בבת ים. עם זאת, כל המקומיים הישראלים ומבקרי המדינה יכולים לקבל את ההנאה הטובה יותר: פגישה עם הבחורות השוות של דירות דיסקרטיות במרכז
You said it adequately..
5 Online Shopping Websites Clothes Tips You Must Know
About For 2023 vimeo.com
The Secret Secrets Of Car Door Lock Repair Price Locking car service
How Slot Demo Gratis Pragmatic Play No Deposit Its Rise To The No.
1 Trend In Social Media demo Slot g
So , You’ve Purchased Shopping Online Sites List … Now What?
Steel Prep Table With Backsplash (https://vimeo.com/931636245)
A Provocative Rant About Double Glazing Near Me double glazed unit Replacement – jinos.Com –
What NOT To Do During The Repair Double Glazed Windows Industry Window Repair
10 Facts About Double Pram And Pushchair That Will Instantly
Put You In An Upbeat Mood pushchairsandprams
7 Helpful Tips To Make The Greatest Use Of Your Online Shopping Figures Uk Cheapest Online Shopping Uk
10 Simple Steps To Start The Business Of Your Dream Online Shopping Sites Top 7 Business
Vimeo
The 10 Most Scariest Things About Online Shopping Stores List online shopping stores list (Guillermo)
A Peek Inside The Secrets Of Slot Online online slots
See What Mobility Scooter For Adults Tricks The Celebs Are Making Use
Of http://www.9i2bz3bx5fu3d8q5a.com
לא יודעות מהם איסורים מוסריים או טאבו על המסאג’. הפצצות המתוקות מסכימות בקלות להתנסויות, תמיד מוכנות לנסות משהו חדש. המטרה שלהן בחיפה צריך להביע את בקשותיו; הבחורות מיד יבואו אליו (או ייפגשו איתו בדירה דיסקרטית), ייראו מדהים, ויהיו נהדרות. עם הבחורות הללו, Escorts Tel Aviv hottest women for you
11 Ways To Completely Redesign Your High Variance Slots evoplay slots recommended
When some one searches for his vital thing, thus he/she wants to be available that in detail, so that thing is maintained over here.
organic ashwagandha by nuzena
Meds information leaflet. Cautions.
where can i buy levonorgestrel
All information about drug. Get information now.
Hello every one, here every one is sharing these know-how, thus it’s fastidious to read
this blog, and I used to go to see this blog daily.
10 Facebook Pages That Are The Best Of All Time About CSGO
Cases Value operation hydra Case