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
At the start of its infamy, fuck was perjorated, which suggests it had an adverse association.
Also visit my site https://www.zillow.com/fairfield-bay-ar/
Asbestos cases can be complicated because they usually involve multiple jurisdictions.
Law firms that have experience processing asbestos Claim claims on the state and national levels know
the specific laws that apply to.
where can i buy full spectrum cbd gummies-spectrum gummies contain trace amounts of
THC.
Joy Organics’ Is Just Cbd Gummies Full Spectrum are also vegan and non-GMO.
generic advair diskus tablets
100 mg doxycycline for acne
I tһink that everything published ԝas aсtually verʏ reasonable.
But, consider thіs, suppose үou added a little
content? Iain’t saying your information isn’t good, bսt suppose yoս added a post title tto
maybe gеt ɑ person’s attention? Ι mean JS 依照元素出現數量排序 – 馬老師 雲端研究室 is
a lіttle boring. Yoou mіght glance аt Yahoo’ѕ front page and
see how they creatе post headlines to get people intеrested.
Yοu might try adding а video ᧐r ɑ reⅼated picture or
two tⲟ get people interested аbout wһat yоu’ѵe ցot to ѕay.
Jսst my opinion, it wouⅼd Ьring yօur posts a little livelier.
Heree іs my site situs judi slot
What’s The Most Important “Myths” About Upvc Patio Doors Could Be A Lie upvc replacement door panel (Kathlene)
Asthma symptom severity tracking aids
When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four e-mails with the same comment.
Is there any way you can remove me from that service? Thanks a
lot!
Our products contain less than 0.3% THC.
My site – what are broad spectrum cbd gummies
10 Reasons Why People Hate Mesothelioma Legal.
Mesothelioma Legal Mesothelioma claim
Cerebral Palsy Attorney: The Good, The Bad, And The Ugly cerebral palsy Law firms
Many reputable CBD brands sell CBD gummies online.
Also visit my site :: Bookmarks
Hi, i think that i saw you visited my web site so i came to “return the favor”.I’m attempting to find things to enhance my website!I suppose its ok to use a few of your ideas!!
You’ll Be Unable To Guess Window Replacement Near Me’s Secrets window Replacement near me
lgbt porn
online slot
Meds information. What side effects?
cost of generic dramamine prices
Everything about meds. Get information now.
cost of cheap cetirizine pill
can i get generic macrobid without prescription
The 10 Most Scariest Things About Assessment Of Adult Adhd adhd diagnostic assessment For adults
lgbt porn
Can I simply say what a comfort to discover an individual
who truly understands what they’re discussing
on the net. You definitely know how to bring an issue to light and make it important.
More and more people need to read this and understand this side of the
story. I was surprised that you aren’t more popular given that you most certainly
possess the gift.
Let’s Get It Out Of The Way! 15 Things About Cerebral Palsy Claim We’re Tired Of Hearing cerebral palsy Law firms
get finasteride pills
оборудование для проведения конференций http://www.oborudovanie-konferenc-zalov11.ru .
конференц залы оборудование конференц залы оборудование .
Looking For Inspiration? Try Looking Up Online Clothes Shopping Websites Uk
which supermarket is Best for online shopping
оборудование для проведения конференций https://oborudovanie-konferenc-zalov11.ru/ .