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
See What Accident And Injury Attorneys Tricks The Celebs Are Using accident and Injury attorneys
medication canadian pharmacy: CanadianMdPharm – canadapharmacyonline legit
5 Killer Quora Answers To Double Glazing Doctor glazing doctor
настроить 1с бухгалтерия цена настроить 1с бухгалтерия цена .
canadian online pharmacy: Canadian Md Pharm – drugs from canada
https://mexicaneasypharm.com/# mexico drug stores pharmacies
canada pharmacy online
There are various tools and websites that claim to allow users to view private
Instagram profiles, but it’s important to right of entry these with caution. Many of these tools can be unreliable, may require personal information, or could violate Instagram’s terms of service.
Additionally, using such tools can compromise your own security or lead to scams.
The safest and most ethical exaggeration to view private instagram profiles 2022 a private profile is to send a follow request directly to the user.
Always prioritize privacy and worship in your online interactions.
canadian pharmacy king https://canadianmdpharm.shop/# canadian pharmacy 365
india pharmacy
This is just what I needed; time to address my roof’s moss problem with help from Roof Cleaning Company
программа 1с купить программа 1с купить .
1с предприятие купить программу 1с предприятие купить программу .
программа 1с купить программа 1с купить .
купить программу 1с бухгалтерия купить программу 1с бухгалтерия .
Thanks for the thorough article. Find more at برگرداندن پست حذف شده اینستاگرام
https://naveridbuy.blogspot.com/2024/11/blog-post_50.html
вывод из запоя в стационаре воронежа вывод из запоя в стационаре воронежа .
canadian pharmacy ltd https://indiancertpharm.shop/# indian pharmacy
best online pharmacy india
https://candid-lion-dd3cm3.mystrikingly.com/blog/53469580831
buy canadian drugs https://indiancertpharm.shop/# Indian Cert Pharm
indian pharmacy paypal
If some one wants to be updated with most recent technologies therefore he must be
go to see this web site and be up to date daily.
my response https://trusteewallet.org
1с предприятие купить программу 1с предприятие купить программу .
best canadian online pharmacy: canadian pharmacy 24h com safe – canada drugstore pharmacy rx
I know this if off topic but I’m looking into starting my own blog and
was wondering what all is needed to get setup?
I’m assuming having a blog like yours would cost a pretty penny?
I’m not very web smart so I’m not 100% sure.
Any recommendations or advice would be greatly appreciated.
Thank you
настройка 1с бухгалтерии цена настройка 1с бухгалтерии цена .
canadian pharmacy antibiotics https://canadianmdpharm.online/# medication canadian pharmacy
pharmacy website india
Mexican Easy Pharm: buying from online mexican pharmacy – Mexican Easy Pharm
программы фирмы 1с программы фирмы 1с .
20 Myths About Retro Red Fridge Freezer: Busted Cheapest Retro Fridge Freezer
купить программу 1с бухгалтерия купить программу 1с бухгалтерия .