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
hurtownia stali bydgoszcz
выведение из запоя в стационаре балашихи выведение из запоя в стационаре балашихи .
canadian drug pharmacy cheap drugs online the best ed drug
online medication: low cost pharmacy – how to fix ed
вывод из запоя на дому в москвае http://www.vyvod-iz-zapoya-moskva13.ru/ .
I couldn’t resist commenting. Exceptionally well written!
образование купить диплом готовый prema-diploms.ru .
Simply wish to say your article is as surprising. The clearness in your put up is simply cool and i can suppose you’re a professional
in this subject. Fine together with your permission allow me to snatch your feed to stay updated with imminent post.
Thank you 1,000,000 and please continue the rewarding work.
mexican drugstore online: mexico pharmacy – mexican drugstore online
Yes! Finally something about việc làm tiếp thị.
https://ohana99.net/เว็บสล็อตมากความสามารถที่ให้มากกว่าความสนุกสนาน
soma therapy ed cheap pharmacy online over the counter ed treatment
вывод из запоя в стационаре москваа http://vyvod-iz-zapoya-moskva12.ru/ .
вывод из запоя анонимно vyvod-iz-zapoya-moskva12.ru .
The Main Issue With Remote Key Repair, And How To Fix It broken key Repair Near Me
Fantastic web site. Lots of useful info here. I’m sending it to a few buddies ans also sharing
in delicious. And certainly, thanks to your effort!
Is Replace Bmw Key Just As Important As Everyone Says?
bmw car key
Вопросы и ответы: можно ли быстро купить диплом старого образца?
purple pharmacy mexico price list mexican pharmacy mexican pharmaceuticals online
Toto Result Explained In Less Than 140 Characters 메이저사이트
Hi! Quick question that’s completely off topic. Do you know how to make your site
mobile friendly? My web site looks weird when browsing from my
iphone 4. I’m trying to find a template or plugin that might be able to
resolve this issue. If you have any recommendations, please share.
Cheers!
купить диплом купить диплом .
Hi there colleagues, pleasant piece of writing and nice urging commented here, I am actually enjoying by these.
pills erectile dysfunction cheaper medications dog antibiotics without vet prescription
куплю диплом рублей diplomdarom.ru .
купить диплом в когалыме prema-diploms.ru .
https://pharm24.pro/# otc ed pills
best erectile dysfunction pills
Have you ever considered about adding a little bit more than just your articles?
I mean, what you say is valuable and all. But just imagine if you added some great photos or videos to give your posts more, “pop”!
Your content is excellent but with pics and video clips, this site could definitely be one of the best in its niche.
Very good blog!
The Best Folding Treadmill UK Tricks For Changing Your Life best folding treadmill uk
15 Gifts For The Mercedes Car Keys Replacement Lover In Your
Life replacement mercedes keys, https://glamorouslengths.com/,