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
Drugs prescribing information. Short-Term Effects.
generic cipro without insurance
Everything about drug. Read information here.
The Atomic Keto Diet
is a popular weight loss program that focuses on achieving ketosis, a
metabolic state where the body burns fat for fuel instead of carbohydrates.
Medicament information for patients. Effects of Drug Abuse.
where can i get generic ropinirole without rx
Some what you want to know about medicine. Get information here.
Medicament information. What side effects can this medication cause?
order cheap zocor tablets
Best information about meds. Get here.
Именно от сюжета зависит интерес игрока к автомату, что является уже частью
успеха.
I’m not that much of a internet reader to be honest but your
sites really nice, keep it up! I’ll go ahead and bookmark your
site to come back later on. Many thanks
Meds information. What side effects?
where buy cheap verapamil tablets
Some news about drugs. Read now.
14 Questions You Shouldn’t Be Afraid To Ask About Semi Truck semi truck Accident Law firms
The 10 Scariest Things About Online Shopping Stores List online shopping stores list
Every weekend i used to pay a visit this site, because i wish for
enjoyment, since this this website conations really good funny information too.
9 Things Your Parents Teach You About Hiring Truck Accident Attorneys truck accident Attorneys
(http://www.guaguabj.com)
Very nice article, just what I wanted to find.
The 10 Most Scariest Things About List Of Online Shopping Sites
In Uk list of online shopping sites in uk, Sabina,
You’ll Be Unable To Guess Online Shopping Uk’s Tricks online
shopping uk (toolbarqueries.google.dk)
jasminer
Секреты ухода за зубами, рекомендуем.
Современные технологии в стоматологии, профессиональный уход за зубами.
Как избежать боли при лечении зубов, изучить.
Мифы о стоматологии, в которые верят все, качественные советы стоматолога.
Секреты крепких и белоснежных зубов, рекомендуем.
Как выбрать хорошего стоматолога, профессиональные методики стоматологии.
Как правильно чистить зубы: секреты здоровой улыбки, предлагаем.
дитяча терапевтична стоматологія https://klinikasuchasnoistomatologii.vn.ua/ .
Как выбрать лучшую клинику стоматологии, изучить.
Современные технологии в стоматологии, качественный уход за зубами.
Эффективные способы обезболивания, предлагаем.
Самые популярные заблуждения о зубах, профессиональные советы стоматолога.
Как избежать проблем с зубами, прочитать.
Лечение зубов без боли: реальность или миф?, эффективные методики стоматологии.
Как избежать неприятного запаха изо рта, прочитать.
дитяча стоматологія https://klinikasuchasnoistomatologii.vn.ua/ .
It is important for an attorney to understand how to identify Asbestos Litigation-related materials in each case.
This can be done by speaking with colleagues in the office, collecting records, and
analyzing samples from homes or workplaces.
If some one wants expert view regarding running a blog afterward i advise
him/her to go to see this web site, Keep up the nice work.
Wonderful blog! I found it while browsing on Yahoo News.
Do you have any tips on how to get listed in Yahoo
News? I’ve been trying for a while but I never seem to get there!
Cheers
Играй и выигрывай вместе с 1win казино
1win зеркало https://xn—-7sbb2afcierdfbl.xn--90ais/ .
Guide To Upvc Repairs Near Me: The Intermediate Guide In Upvc Repairs Near Me upvc repairs Near Me
We guarantee the high quality in our items.
My blog post :: mushroom head cc cream foundation reviews
Incontestable Evidence That You Need Upvc Windows Repair Upvc window repairs near me
What’s The Current Job Market For Window
Repair Near Me Professionals? window repair near me
(Loren)
Medicines information sheet. Long-Term Effects.
cost indomethacin online
Best information about medicines. Read information now.
It’s very trouble-free to find out any matter on web as
compared to books, as I found this post at this website.
Hi there, I found your blog by way of Google at the same
time as searching for a comparable matter, your web
site came up, it appears to be like great. I have bookmarked it in my google bookmarks.
Hello there, simply became alert to your blog through Google, and located that it is truly
informative. I am gonna watch out for brussels.
I will appreciate when you proceed this in future.
A lot of folks can be benefited from your writing.
Cheers!
prednisone dosage costco
5 Killer Quora Answers To Car Accident Attorneys attorneys