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
Реально ли приобрести диплом стоматолога? Основные этапы
prednisone 5 mg brand name: ray pharm – prednisone prescription online
prednisone 5 50mg tablet price: prednisone – prednisone 12 tablets price
darknet market lists darknet links https://darknetmarketstore.com/ – dark market url
http://webcocktail.ru/ — Ознакомьтесь с нашими кухнями, которые идеально подойдут для вашего дома.
Как приобрести аттестат о среднем образовании в Москве и других городах
Hello to all, it’s actually a good for me to visit this website, it consists of useful Information.
prednisone acetate: order Prednisone – how to get prednisone without a prescription
cheap clomid now: cheap clomid – cost cheap clomid online
Реально ли приобрести диплом стоматолога? Основные шаги
Hello there I am so excited I found your web site,
I really found you by mistake, while I was looking
on Askjeeve for something else, Nonetheless I am here now and
would just like to say many thanks for a tremendous post
and a all round entertaining blog (I also love the theme/design), I don’t have time
to read it all at the moment but I have bookmarked it and also added
in your RSS feeds, so when I have time I will be back to
read much more, Please do keep up the excellent b.
Вопросы и ответы: можно ли быстро купить диплом старого образца?
Also visit my blog post – Daycares By Category
get cheap clomid for sale: clomid – cost of clomid online
Link exchange is nothing else except it is simply placing the other person’s web site link on your page at proper place and other person will also do same
in favor of you.
Приобретение школьного аттестата с официальным упрощенным обучением в Москве
can i purchase ventolin pills
Quality posts is the secret to attract the viewers to pay a quick visit the website,
that’s what this website is providing.
нарколог на дом срочно нарколог на дом срочно .
Купить диплом ВУЗа России
Как быстро получить диплом магистра? Легальные способы
Hi, I ԁo ƅelieve this is an excellent website.
I stumbledupon іt 😉 I may rethrn oncе agaіn since Ӏ saved as a favorite іt.
Money and freedom is thе bеѕt way to ϲhange, may ʏou
be rich and continue to һelp other people.
Check οut my web site … WengToto
вызов нарколога на дом круглосуточно https://www.motik13.0pk.me/viewtopic.php?id=1995 .
Hey There. I found your blog using msn. This is an extremely smartly written article.
I’ll make sure to bookmark it and come back to learn more of
your helpful information. Thank you for the post.
I will certainly comeback.
Voce teve um sonho incomum?
Olhar num espelho num sonho
[url=https://waynecountynyjobs.com/2022/06/18/blog-digital-ocean/#comment-14019]Com que e que um elefante sonha?[/url] [url=https://dangerouscellphone.com/hello-world/#comment-251860]Sonho de um gato adormecido[/url] [url=https://tomachupicchutravel.com/salkantay-trek-on-your-own/#comment-34037]Num sonho, apanhar coisas[/url] [url=http://gawontech.com/bbs/board.php?bo_table=o_01&wr_id=47749]Com que e que um el[/url] [url=http://n51.com.sg/en/component/k2/item/1-fusce-euismod-tincidunt-purus-vitae]Sonha com um cao que morde o seu braco? Doeu e sangrou? Interpretacao de um sonho de acordo com diferentes livros de sonho[/url] 4d51_86
Купить диплом старого образца, можно ли это сделать по быстрой схеме?
d91652pj.beget.tech/2024/10/20/poluchite-diplom-prosto.html
I will right away grasp your rss feed as I can not find your e-mail subscription hyperlink or newsletter
service. Do you’ve any? Please allow me understand
so that I may just subscribe. Thanks.
Visit my blog … random video chat
prednisone generic brand name: Prednisone Without Prescription – prednisone 60 mg price
Как приобрести диплом техникума с минимальными рисками
Hello, this weekend is fastidious for me, since this point in time i am reading this great informative post here at my house.