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
Tadora: mobile rx pharmacy – can you buy viagra at the pharmacy
The Sage Advice On Ashley Furniture Pull Out Couch From An Older Five-Year-Old corner sofa pull out
Does your blog have a contact page? I’m having a
tough time locating it but, I’d like to send you an email.
I’ve got some creative ideas for your blog you might be interested in hearing.
Either way, great website and I look forward to seeing
it expand over time.
Real HGH Rewards (NewULife Hgh Gel Not Evaluated Yet).
Also visit my webpage :: ranch Wedding venues fort Worth texas
Plant-based vapes have a host of possible advantages.
Also visit my web site: is vape juice vegan
seneng banget liat video tentang child porn di link anak kecil diperkosa sampai mati
bikin pengen onani terus bosku
PXL Дизайн человека https://humandesignplanet.ru Дизайн человека. 5/2 Дизайн человека.
Allow me show you shoulder surgery specialist in charlotte nc my review of NewULife.
Ꮋі, I Ԁ᧐ beliеve thiѕ iѕ аn exceklent web site.
Ι stumbledupon it 😉 I mayy come back үеt agaіn ѕince і hаve book-marked it.
Money аnd freedom iis the ցreatest way to ⅽhange, may you be ricdh and continue
to guide otһers.
Stop ƅү my homepаge SajiToto Link
USP human development hormonal agent (somatropin).
My homepage – replacement windows at lowe's
Lobsters is a computing-targeted group centered all-around website link aggregation and discussion. The true intercourse – when all through the partnership and after decades afterwards, as a haunting specter conjured in a safety hearing – is temporary and relatively mechanical, while a extended postcoital dialogue has Murphy and Pugh sitting down naked in armchairs on reverse sides of a space, thoroughly positioned and framed to hold crotches out of sight. After enough time passes, a civilisation casts out its prior idealistic identity in favour of creating a new 1, working with the prospects of present day technological innovation and fast generation to build an graphic centered all around modern day pragmatism alternatively than historical myths. Image proxy/viewer that shows pictures from many web-sites in comic book sort. Learn and observe stability concepts in the kind of pleasurable-loaded online games. Cool educational browser games. Of the 952,316 individuals in the Advance weight cohort, 559,134 (58.7%) had been from OCHIN clinics, 373,555 (39.2%) had been from HCN clinics, and 19,627 (2.1%) ended up from FHI ( Table 1). Age and sexual intercourse were being very similar for OCHIN and HCN individuals. There ended up 137,445 individuals with diabetic issues in the Advance bodyweight cohort (14.4%), ( Table 2). Patients with diabetes had been noticeably more mature and far more possible to be male and nonwhite than were sufferers without the need of diabetic issues.
Use the most detailed lawful catalogue of forms.
Stop by my site :: bankruptcy lawyers near me for low income
My Arizona Attorney assisted me with my criminal case.
Here is my web page bankruptcy lawyers dallas texas
The larger Slim battery, fantastic for longer runtimes.
Review my web page – Foil Drive Assist Max
naltrexone river pharmacy: atlantic pharmacy viagra – online pharmacy lortab
Expert Advice On Car Key Programmer From The Age Of Five Car key reprogram
Some individuals vegan vape juice brands
flavorful nicotine
My Arizona Lawyers assisted me with my criminal case.
Feel free to surf to my homepage :: what is chapter 13 bankruptcies
kamagra online pharmacy uk: charles raines pharmacy winston-salem nc early drug store – crestor people’s pharmacy
Sahabet Casino’da yeni oyuncular, en yuksek bonusu alarak kazanmaya baslayabilir. En sevilen slotlar Sahabet’te kazananlar?n? bekliyor. Sans?n?z? simdi deneyin ve ilk depozitoda buyuk avantajlar kazan?n. Sahabet, yeni y?lda kazand?ran kumarhane olarak dikkat cekiyor.
over the counter online pharmacy: skelaxin online pharmacy – compare rx prices
USP human development hormone (somatropin).
Here is my blog; windows replacement cost home depot
How Do You Explain Upvc Windows And Doors To A
5-Year-Old upvc Window Repairs
I all the time used to study paragraph in news papers but now as I am a user of internet thus from now I
am using net for articles, thanks to web.
You can expect lenders to call till you submit.
Review my homepage; Bookmarks
In this situation, the life insurance policy firm’s money.
My web blog; Bookmarks
They have items to market or services to use.
Feel free to surf to my page: ceramic craft studio near me
Childrens Bunk Beds Tools To Help You Manage Your Daily Lifethe
One Childrens Bunk Beds Trick That Should Be Used By Everyone Learn Childrens bunk beds
Зарегистрируйтесь на https://888starz.today и получите свои бонусы за первый депозит.
USP human growth hormonal agent (somatropin).
Here is my webpage :: Bookmarks