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
John Leslie, previous presenter of British tv reveals Blue Peter and This Morning, manufactured a home video of himself receiving oral sex from his actress/nurse girlfriend Abi Titmuss in 2000. He also filmed Titmuss undertaking and receiving oral intercourse with one more lady. So what do you actually consider about relationships in online video online games? Change your frame of mind toward giving him oral enjoyment. You are not “ignorant” and participating in heterosexual oral sex does not make you “more gay”. Partners want to be genuine and down-to-earth about sexual intercourse during being pregnant. You may locate that pregnancy complements your feeling of sexuality, earning you experience far more feminine and fascinating or, on the other hand, you may well experience uncomfortable and unattractive. This is the most barebones, no-bullshit app for everyday intercourse you could potentially obtain. In instances of incompetent cervix or a heritage of cervical weak point or, a low-lying placenta or placenta previa, the physician could say it is really greatest not to have intercourse for the rest of your being pregnant.
10 Sites To Help You Become An Expert In Symptoms Of Adhd In Adults symptoms Of adhd in adults checklist
капельница от запоя стоимость капельница от запоя стоимость .
Definitely believe that that you said. Your favourite reason appeared to be on the net the simplest
thing to keep in mind of. I say to you, I definitely get
irked whilst folks think about concerns that they
just don’t realize about. You controlled to hit the nail upon the highest as smartly as defined out the whole thing with
no need side effect , other folks can take a signal.
Will likely be back to get more. Thanks
Great web site you’ve got here.. It’s hard to find excellent writing like yours
nowadays. I seriously appreciate individuals like
you! Take care!!
Is Kucoin Available In Canada
prices pharmacy: cymbalta discount pharmacy – publix pharmacy online ordering
Здравствуйте!
Мы готовы предложить дипломы любых профессий по приятным ценам.
kiopro.ru/support/forum/view_profile.php?UID=72504
How To Create An Awesome Instagram Video About Skoda Replacement Key
Near Me skoda Octavia key; telegra.Ph,
выведение из запоя https://www.vyvod-iz-zapoya-rostov12.ru .
POY Дизайн человека https://raschet-karty-dizayn-cheloveka.ru Дизайн человека. 4/6 Дизайн человека.
you’re in reality a good webmaster. The website loading velocity is amazing.
It kind of feels that you are doing any unique trick.
Also, The contents are masterwork. you’ve performed a fantastic job on this topic!
celebrex pharmacy coupon: ciprofloxacin pharmacy – uk pharmacy
Guide To Get A Spare Car Key Made: The Intermediate Guide To Get A Spare
Car Key Made get a spare car key made
The 15 Things Your Boss Would Like You To Know You’d Known About Zeus Hades Oscarreys.Top
online pharmacy australia viagra: advair pharmacy coupons – french pharmacy online store
Guide To Lightest Folding Electric Wheelchair: The Intermediate Guide On Lightest Folding
Electric Wheelchair lightest folding electric wheelchair
See What Titration ADHD Adults Tricks The Celebs Are Utilizing titration adhd adults
Excellent post. I’m experiencing many of these issues as well..
Super Avana: custom rx pharmacy kuna – medicine store pharmacy springfield, mo
NewULife Ranks. Welcome to my NewUlife Review.
My web blog: replacement windows for sale
That is a great tip particularly to those new to the blogosphere.
Short but very precise information… Many thanks for sharing this one.
A must read article!
20 Myths About ADHD Test Adults: Busted adult adhd tests [Chunzee.Co.kr]
drug costs: pharmacy online 365 reviews – online pharmacy pyridium
Hello, after reading this awesome piece of writing i am also
happy to share my know-how here with colleagues.
USP human growth hormonal agent (somatropin).
Feel free to visit my blog Bookmarks
снятие ломки цены снятие ломки цены .
Bandar Online Togel Tools To Ease Your Daily Life Bandar Online Togel Trick That Should Be Used By Everyone Learn Bandar online Togel
online slot
Hey there just wanted to give you a quick heads up and let you know a
few of the images aren’t loading correctly. I’m not sure why but I think
its a linking issue. I’ve tried it in two different internet browsers and both
show the same results.