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
Быстрая схема покупки диплома старого образца: что важно знать?
best way to treat ed low cost prescription buy prescription drugs online without
14 Smart Ways To Spend Your The Leftover Latest Sport Toto Result Budget 먹튀검증
treatment for ed http://mexicanpharm24.cheap/# mexican drugstore online
Официальная покупка диплома вуза с сокращенной программой в Москве
ed dysfunction treatment http://mexicanpharm24.cheap/# mexican border pharmacies shipping to usa
Hmm is anyone else having problems with the images on this blog loading?
I’m trying to figure out if its a problem on my end or
if it’s the blog. Any feed-back would be greatly appreciated.
https://w4.datasingapore.club/
Woah! I’m really digging the template/theme of this site.
It’s simple, yet effective. A lot of times it’s hard to get that “perfect balance” between usability
and visual appeal. I must say you’ve done a excellent job with this.
Also, the blog loads super quick for me on Opera. Excellent Blog!
Guide To Replacing Upvc Door Panel: The Intermediate Guide The Steps To Replacing Upvc Door Panel Replacing
upvc door panel (https://fakenews.win/wiki/17_Signs_To_Know_You_Work_With_Replacement_Panel_For_Upvc_Door)
Is Your Company Responsible For The Car Key Cutters Near Me Budget?
12 Tips On How To Spend Your Money Motorcycle Key Cutting (Funder-Hansen-3.Blogbright.Net)
cordarone antiarrhythmic drugs made
10 Meetups On Online Mystery Box You Should Attend best gaming mystery
box, Sung,
Купить диплом о среднем образовании в Москве и любом другом городе
Best SEO Agency London: 11 Thing You’re Forgetting To Do London Seo Consulting (Fallesen-Mcclain.Technetbloggers.De)
Thanks designed for sharing such a pleasant thought, piece of writing is
good, thats why i have read it completely
Look into my web page zapada01
Greetings! I’ve been reading your site for a while now
and finally got the bravery to go ahead and give you a shout out from Huffman Tx!
Just wanted to mention keep up the excellent work!
Feel free to surf to my blog MARKETSLOT
I love what you guys are up too. This kind of clever work and reporting!
Keep up the fantastic works guys I’ve included
you guys to blogroll.
Visit my blog – Mesin Slot
http://pharm24.pro/# cause of ed
over the counter ed treatment
herbal remedies for ed https://mexicanpharm24.cheap/# mexico drug stores pharmacies
Wonderful work! That is the kind of information that are supposed to be shared across the internet.
Shame on Google for now not positioning this publish
upper! Come on over and talk over with my website . Thank you =)
Всё о покупке аттестата о среднем образовании: полезные советы
top 10 online pharmacy in india: Indian pharmacy worldwide delivery – india pharmacy mail order
discount prescription drugs https://pharm24.pro/# psychological ed treatment
11 Methods To Totally Defeat Your Driving License Category C+E Total Cost
Prawo jazdy a1
best ed treatment pills https://indianpharm24.pro/# top 10 online pharmacy in india
Hi there, its fastidious article on the topic of media print, we all
understand media is a fantastic source of information.
Сколько стоит получить диплом высшего и среднего образования легально?
What’s The Job Market For ADHD Assessment For Adults Free Professionals Like?
adhd assessment For adults
best male ed pills: cheaper medications – foods for ed
5 Tools That Everyone Working Who Works In The
Double Glazing Seal Repair Industry Should Be Utilizing bifold door seal repair
– Johnette –