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
Awesome postings Thank you!
https://iverfast.com/# stromectol price
Do you mind if I quote a few of your posts as long as I provide credit and sources back
to your website? My blog is in the exact same area of interest as
yours and my visitors would really benefit from a lot of the information you provide here.
Please let me know if this okay with you. Many thanks!
Great post. I was checking constantly this blog
and I am impressed! Extremely useful info specifically the last part 🙂 I care for such
info much. I was seeking this certain info for a very
long time. Thank you and good luck.
Полезная информация как купить диплом о высшем образовании без рисков
Всё, что нужно знать о покупке аттестата о среднем образовании
moneysweet.listbb.ru/viewtopic.php?f=2&t=4955
На нашем сайте вы сможете купить дженерики в СПБ с доставкой курьером в день заказа подробности по ссылке
https://men78.ru гарантированное качество от производителя на все препараты для повышения потенции
10 Meetups About Fabric Corner Recliner Sofa You Should Attend Navy Fabric Corner Sofa
шпон Видное
Покупка диплома о среднем полном образовании: как избежать мошенничества?
cyberpinoy.net/create-blog/
I really like your blog.. very nice colors &
theme. Did you create this website yourself or
did you hire someone to do it for you? Plz respond as I’m looking to create my own blog and would like to know where u got this from.
cheers
where can i get cheap betnovate pill
Awesome information Kudos!
cost generic clomid pill: cheap clomid – can you get generic clomid
lisinopril 20mg: Lisinopril 1st – lisinopril1st
fonbet by fonbet by .
These are actually enormous ideas in regarding blogging.
You have touched some good factors here. Any way keep up wrinting.
Hi there! I’m at work browsing your blog from my new iphone 3gs!
Just wanted to say I love reading through your blog and look forward to all your posts!
Keep up the superb work!
Аттестат 11 класса купить официально с упрощенным обучением в Москве
Heya! I’m at work surfing around your blog from my new apple iphone!
Just wanted to say I love reading through your blog and look forward to all your posts!
Carry on the outstanding work!
Всё, что нужно знать о покупке аттестата о среднем образовании без рисков
Процесс получения диплома стоматолога: реально ли это сделать быстро?
https://lisinopril1st.com/# lisinopril1st
The cultural experiences in Dubai are unforgettable! Thanks to dubai hatta tour for the amazing recommendations
кухни на заказ цены — Узнайте стоимость изготовления кухонь на заказ.
Great post. I was checking constantly this blog and I’m impressed!
Very helpful information specifically the last part 🙂 I care for such
info a lot. I was looking for this particular information for a long
time. Thank you and good luck.
Можно ли быстро купить диплом старого образца и в чем подвох?
You’ll Never Be Able To Figure Out This Adult Toys For Couple’s Tricks adult toys for couple (Yonghyeonip.com)
Everything composed was very reasonable. However, think on this, what if you were to create a killer headline?
I mean, I don’t want to tell you how to run your website, but what if you added a
title to possibly get a person’s attention? I mean JS 依照元素出現數量排序 – 馬老師 雲端研究室 is a little boring.
You could glance at Yahoo’s home page and watch how
they create post headlines to get viewers interested.
You might add a related video or a related pic or two to grab people interested about everything’ve
got to say. Just my opinion, it might bring your posts a little bit more interesting.
Купить диплом старого образца, можно ли это сделать по быстрой схеме?
maxima.2ua.in.ua/viewtopic.php?f=3&t=6453