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
Как приобрести аттестат о среднем образовании в Москве и других городах
buy prescription drugs from india: indian pharmacy purchase online – top 10 online pharmacy in india
Вопросы и ответы: можно ли быстро купить диплом старого образца?
which ed drug is best: cheap meds – natural ed
ed online pharmacy https://mexicanpharm24.cheap/# medication from mexico pharmacy
Как безопасно купить диплом колледжа или ПТУ в России, что важно знать
muse for ed https://pharm24.pro/# vitality ed pills
Prams For Sale Tools To Streamline Your Daily Life Prams For Sale Trick Every Person Should Learn prams For Sale
Приобретение диплома ПТУ с сокращенной программой обучения в Москве
Can I simply just say what a comfort to discover somebody who actually understands what they’re
talking about on the web. You actually know how to
bring an issue to light and make it important. A lot more people have to read this
and understand this side of your story. I can’t believe you aren’t more popular since you
certainly possess the gift.
Аттестат школы купить официально с упрощенным обучением в Москве
forumex.forumex.ru/viewtopic.php?f=7&t=184
Всё, что нужно знать о покупке аттестата о среднем образовании без рисков
aviantrp.moibb.ru/viewtopic.php?f=8&t=248
Официальная покупка диплома вуза с сокращенной программой обучения в Москве
reputable mexican pharmacies online: mexican drugs – п»їbest mexican online pharmacies
купить диплом в новошахтинске orik-diploms.ru .
That is a really good tip especially to those fresh to the
blogosphere. Short but very accurate information… Appreciate your sharing this one.
A must read post!
online pharmacy india indian pharmacy purchase online reputable indian online pharmacy
Удивительно, но купить диплом кандидата наук оказалось не так сложно
15 Startling Facts About 2 In 1 Stroller Car Seat You’ve Never Heard Of Baby Prams 2 In 1
The Top Reasons People Succeed In The 50 50 Fridge Freezer With Water
Dispenser Industry fridge freezer with ice and water
The One Glass Pane Replacement Mistake Every Newbie Makes double
10 Quick Tips On Asbestos Attorney In Virginia mesothelioma lawyers
(Ellie)
https://pharm24.pro/# ed remedies
canadian drugs online
Легальная покупка диплома о среднем образовании в Москве и регионах
Bet303.com is operated by Codex B.V., a company incorporated under the laws of Curaçao with Company Number 160873 and has a valid Certificate of Operation. This Certificate of Operation is subject to the
National Ordinance on Off shore Games of Hazard.
No one has a right to your body,ロボット セックス just like you don’t have any rights to anyone else’s body. If you don’t want to take part in sexual activities, it’s your right to say no. Sexual consent is a must-have, every time you have sex.
What Is Adhd Assessment And Why Is Everyone Dissing It? How Do You Get Assessed
For Adhd – https://Privateadhdassessment20515.Yomoblog.Com –
http://indianpharm24.pro/# online pharmacy india
buy prescription drugs without doctor
купить диплом кандидата отзыв orik-diploms.ru .
Вопросы и ответы: можно ли быстро купить диплом старого образца?