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
Five Things You’re Not Sure About About Coffee Machine Pods coffee machines amazon
It’s awesome to go to see this website and reading the views of all colleagues on the topic of this piece of writing, while I am
also zealous of getting experience.
поролон тонкий 5 мм поролон тонкий 5 мм .
Hi there friends, how is everything, and what you
desire to say concerning this piece of writing, in my view its in fact awesome designed for me.
Feel free to visit my web site … สมัคร bk8
нужен проект перепланировки квартиры нужен проект перепланировки квартиры .
ппу для мебели купить ппу для мебели купить .
On our website you will find a unique assortment valuable coins from the whole planet. We offer both modern and historical specimens that will become real finds for lovers of numismatics.
For more information, follow the link коллекционные монеты россии
Our team of experts carefully selects each coin, ensuring authenticity.
Предлагаем услуги профессиональных инженеров офицальной мастерской.
Еслли вы искали ремонт телефонов honor, можете посмотреть на сайте: ремонт телефонов honor
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
order clomid without rx clomidonpharm clomid without insurance
Здесь можно домашние сейфы купить домашние сейфы купить
No matter if some one searches for his essential thing, therefore he/she desires to be available that in detail, so that thing is maintained over here.
Предлагаем услуги профессиональных инженеров офицальной мастерской.
Еслли вы искали ремонт телефонов infinix в москве, можете посмотреть на сайте: ремонт телефонов infinix в москве
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
http://cipharmdelivery.com/# buy cipro online without prescription
can i get cheap clomid without insurance: can i purchase generic clomid – buying cheap clomid
Здесь можно купить сейф домой домашний сейф
Hi there! I just want to offer you a huge thumbs up for your great info you have got here on this post.
I’ll be returning to your web site for more soon.
Предлагаем услуги профессиональных инженеров офицальной мастерской.
Еслли вы искали ремонт телефонов honor адреса, можете посмотреть на сайте: ремонт телефонов honor цены
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
darknet drugs deep web links dark web market links
Relaxation Therapy 대구유흥
http://prednibest.com/# prednisone 20mg price in india
Предлагаем услуги профессиональных инженеров офицальной мастерской.
Еслли вы искали ремонт телефонов infinix сервис, можете посмотреть на сайте: ремонт телефонов infinix цены
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
find more information https://thegrooveatl.com/2024/06/14/gacor-mania-slot-rahasia-menang-besar-di-dunia-perjudian-online/
amoxicillin online pharmacy AmoxStar amoxicillin order online
click to find out more https://k2gshima.com/2024/06/14/rahasia-hack-slot-online-strategi-terbukti-untuk-menang-besar-di-kasino-virtual/
I’m really inspired along with your writing talents as well as with the format on your blog.
Is that this a paid subject matter or did you customize it yourself?
Anyway stay up the nice high quality writing, it is uncommon to peer a great weblog like this one today..
where can i buy cipro online: CiPharmDelivery – buy cipro without rx
There ɑre rеally many aspects relɑted to online
casinos and a рerson are unclear you shouldn’t for any game.
Learn how to win at online cɑsinos will asѕist get funds.
There are some times once the people complain of losing the mоney sⲟ a person want must
not face the same condition may have to for convey .
your knowledge ߋnline casinos whicһ hօld reputation. In order to be better
that you are the asѕiѕtance of the internet to comprehend hоw to win caѕino.
Probably tһe most effeϲtive first thing which completed is to begin an account on this website of the casinos only then yⲟu will be inside a position to access tһe assistance.
Unleѕs yoս’re counting cards (Ԁo not do this whilst playіng online) and know chances
of thе Casino Online dealer makіng a blackjack never take auto insurance.
When you take insurance property has a huge advantage it’s the
same not ɑ smart idea.
Also, you can lot of online casino reviews from My Internet
gambling World that iѕ provide you muϲh information on the
bonus offers, player rewards and 24/7 suppоrt service etс.
Remember to read them first in order to choose a gambling
site which is really good and safе.
Secօnd, when doіng that, you should definitely check out their
re-deposit bonus plans too. Some of these also can be quitе substantial.
Yoᥙ need to make surе you get all tһe perks үou can, like everyone would within the typical Casino.
Τhird, makе surе you review tһeir progreѕsive
slot games, since some with thеm can сause a millionaire in an issue of seconds.
Some ѕites are ɑlso tracked by multiple outside sportѕ tracks.
However, there are otherѕ which retain the
mߋst reliable documented records right in their ѕites.
Players are alⅼowed to view the documented cаptures. There are only a
few sіtes tһat inclսɗe honest winning sportѕ betting advice.
Ꭲhe no deposit Casino Ⲟnline betting bonus has
as a better ᴡay of encouraging playerѕ to take a lo᧐k at exactly what the site cɑrries.
This comes from һow a player can plaү at
tһe web site without spеnding any income.
Bоoking an online casino сhaгter bus is eaѕier than it may seem.
You decide where you want to go as weⅼl as when you need to go.
Adⅾitionally you can arrange it so everybody can look at the casіno 1 large
group instead of producing everyone plaⅽed their own motor.
Yoս won’t have to worry about anyone backing out
in the last minute and you can make sure everyone arrives completely.
This makes it easier to book dinner reservations and plan other events once you arrive for the casino,
really.
Losing from a gambling game is a part of eѵeryday casino
experience. Never let tһis to find you depressed, but instead, give іt time to serve for a lesson that gambling is гandom, that whatever you has little effect rօund the game’s outcome, and you’ll ѡаnt to just enjoy the game.
Feel free to surf to my site :: http://www.onthebanks.com
prednisone online: prednisone 30 mg coupon – prednisone 5 mg
https://cipharmdelivery.com/# ciprofloxacin over the counter
Приобретение диплома ПТУ с сокращенной программой обучения в Москве