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
deneme bonusu veren casino siteleri guvenilir casino siteleri en guvenilir casino siteleri
Thanks for the great explanation. More info at استخدام نیروی نمایشگاهی
Thanks for sharing this info about roof maintenance—so crucial for homeowners in Bellingham Roof Cleaning Service
slot siteleri: guvenilir slot siteleri – slot casino siteleri
Hurrah, that’s what I was exploring for, what a material!
present here at this web site, thanks admin of this site.
Thanks for the helpful advice. Discover more at رنگ ضد حریق
sweet bonanza sweet bonanza kazanma saatleri sweet bonanza kazanma saatleri
Components For Building Amazing Chiropractic Business Empire OP
вывод из запоя стационар ростов вывод из запоя стационар ростов .
вывод из запоя на дому цена вывод из запоя на дому цена .
Love the focus on sustainable plumbing solutions in your articles—keep it up! 24/7 Plumber
I lately started a blossom yard, and it’s been so fulfilling! The delight of nurturing plants is something every person must experience. Discover suggestions on horticulture at flower shops san francisco
I was fretted about security when leasing a bounce house, yet the firm I made use of from water slide rentals near me had impressive testimonials and excellent tools
提供最新搜狗输入法下载服务,适用于Windows、Mac、Android和iOS设备。支持拼音、五笔、语音输入多种输入方式,词库丰富,输入流畅精准。更有智能联想、个性化皮肤和表情推荐功能,满足多场景输入需求。立即下载搜狗输入法,畅享高效、便捷、个性化的输入体验!https://www.sogoushurufa.org/ xoajmjde
Most modern analysts permit that will certainly is a lot more usual in almost
all uses.
слоты
капельница от запоя ростов на дону капельница от запоя ростов на дону .
sweet bonanza slot sweet bonanza demo oyna sweet bonanza
” A lot of over the counter therapies will certainly have a concentration under 16 percent peroxide,” she discusses.
вывод из запоя в стационаре ростова http://www.vyvod-iz-zapoya-rostov27.ru .
By seeing a skin specialist, you’ll discover what’s going on which can bring assurance.
slot casino siteleri slot oyunlar? slot oyunlar?
What’s The Current Job Market For Evolution Baccarat Experience Professionals Like?
에볼루션 룰렛
Furthermore, it can provide information regarding the products made use of
in creating these improvements.
I every time spent my half an hour to read this webpage’s content all the time
along with a cup of coffee.
Also visit my webpage: oud aceite esencial
This action can differ relying on the certain peptide and the receptor it binds to.
en kazancl? slot oyunlar? slot siteleri en cok kazand?ran slot oyunlar?
yeni deneme bonusu veren siteler: yeni deneme bonusu veren siteler – deneme bonusu veren siteler
Cell Phone: The Past, The Present And The Long Run 다바오다운로드
This was nicely structured. Discover more at عمل prk