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
Неправильное введение, промокод использован или не актуален или он
был доступен только для определенных регионов или типов аккаунтов.
Nine Things That Your Parent Teach You About Situs Togel Terpercaya situs togel Terpercaya
Thank you for every other magnificent article.
Where else may just anybody get that kind of information in such
a perfect approach of writing? I have a presentation subsequent week, and I am at the search for such info.
Are You Responsible For The Asbestos Attorney
Budget? 12 Top Ways To Spend Your Money mesothelioma lawyers; Landon,
Medicament information leaflet. Short-Term Effects.
buying ceftin
Some what you want to know about medicament. Get here.
купить аттестат за 9 prema-diploms.ru .
how to get prescription drugs without doctor: cheap prescription drugs – ed devices
Spot on with this write-up, I truly believe that this website needs a
great deal more attention. I’ll probably be returning
to see more, thanks for the information!
mexican rx online mexican drugs buying prescription drugs in mexico online
cheap ed drugs: cheap pharmacy online – drug prices
https://mexicanpharm24.cheap/# mexican border pharmacies shipping to usa
aspirin and ed
mexican pharmaceuticals online mexico pharmacy cheap buying prescription drugs in mexico online
I am sure this paragraph has touched all the internet users, its
really really good post on building up new blog.
Как избежать рисков при покупке диплома колледжа или ПТУ в России
Купить онлайн металл в нашем интернет магазине достаточно просто. Для этого вам необходимо перейти в интересующий вас раздел из нашего каталога дешевый металл
10 Startups Set To Change The Crawley Window Repair Industry
For The Better double glazing door repair
http://mexicanpharm24.cheap/# reputable mexican pharmacies online
sildenafil without a doctor’s prescription
mexican mail order pharmacies mexican pharmacy п»їbest mexican online pharmacies
buy anti biotics without prescription http://mexicanpharm24.cheap/# mexican online pharmacies prescription drugs
ed medication http://mexicanpharm24.cheap/# mexican rx online
Free Download the best premium WordPress Premium Plugin Free Download Themes, Plugins, and templates with plan. 100 original with GPL Licensed & free update.
купить диплом вуза ссср prema-diploms.ru .
Guide To Situs Toto Togel: The Intermediate Guide For Situs Toto Togel Situs Toto Togel
drug pharmacy: cheaper medications – ed pills cheap
See What Sex Machines For Sale Tricks The Celebs Are Utilizing sex machines for Sale
best online pharmacies in mexico Mexican pharmacy ship US mexican online pharmacies prescription drugs
Learn About Getting An ADHD Diagnosis While You Work From At Home Adhd Checklist
20 Best Tweets Of All Time ADHD Private Diagnosis who can diagnose add in adults
buying prescription drugs in mexico: mexican pharm 24 – п»їbest mexican online pharmacies
What Is Mesothelioma’ History? History Of Mesothelioma mesothelioma lawyer
(Jacob)