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
USP human development hormone (somatropin).
Also visit my website – Bookmarks
Medicament prescribing information. What side effects?
can i order cheap tolterodine pills
Actual about medication. Read here.
This post is priceless. When can I find out more?
It worked. City officials noticed water consumption plummet.
Flick thru the net collections of waterproof journey cases new
zealand.
my homepage … Custom jewellery box travel
9 . What Your Parents Taught You About Double Glazed Window Suppliers Near Me double Glazed window suppliers near me
It’s really very complex in this full of activity
life to listen news on Television, so I just use web for that reason, and take the latest information.
Pills information sheet. What side effects can this medication cause?
how can i get generic imodium for sale
Actual about medication. Read information now.
I know this web site presents quality based content and extra stuff, is
there any other web page which provides these kinds
of stuff in quality?
Asbestos settlement
victims are given a certain amount of time to file lawsuits under the
law called statutes of limitations. After a lawsuit is filed the lawyers for both sides gather
evidence in a process known as discovery.
What’s The Job Market For Double Glazing Showrooms Near Me Professionals Like?
Local Double Glazing Companies
can you buy requip without prescription
Meds information for patients. Long-Term Effects.
get divalproex without rx
Actual trends of medicament. Get now.
Lorem Ipsum has been the industry’s standard dummy text https://mjoelnirsseite.de/zjheh of type and scrambled it to make a type specimen book.
Proofing is the extremely last phase in editing a book editing software free.
Приветствую. Может кто знает, где почитать разные блоги о недвижимости? Пока нашел https://1eve1.ru
Pills information sheet. Long-Term Effects.
can i buy cheap proscar without prescription
All information about drug. Get here.
Five Killer Quora Answers On Online Shopping Uk Women’s
Clothing online shopping uk women’s clothing
Столешницы, барные стойки, подоконники и другие изделия из искусственного камня от производителя мебели из камня “Акрилиум” https://xn—-8sbemfmhced0ala1ajk.xn--p1ai/article/furniture/8087/
They have items to offer or services to provide.
Stop by my website … stop motion animation online free
how to get generic finasteride without insurance
How To Survive Your Boss On Double Glazing
Company Near Me Repair Double Glazed Window (https://Images.Google.Com.Au/)
I’m not sure where you are getting your information, but good topic.
I needs to spend some time learning much more or understanding more.
Thanks for wonderful info I was looking for this information for my mission.
The Motive Behind Repair Upvc Windows Is Everyone’s Obsession In 2023 upvc windows repair
I don’t even know how I ended up here, but I thought this post was great.
I do not know who you are but certainly you’re going to a famous blogger if you
aren’t already 😉 Cheers!
Non-allergic hives causes
can you buy generic cipro without prescription
jasminer
You’ll Never Guess This SEO Company Near Me’s Secrets seo Company near me
Five Killer Quora Answers To Railroad Injury Fela Lawyer Railroad Injury fela lawyer
Medication prescribing information. Drug Class.
lyrica pills
Actual what you want to know about meds. Read now.