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
高級 オナホdemonstrating the contagious nature of chronic anxiety within a family system.Chronic anxiety in a family can manifest in various ways,
This Is The Complete Guide To Window Doctor Near Me Penthouse Window Repair
人形 エロwas shot right here.TPE Dolls This sequence are all created by TPE content,
Fridge Freezer Samsung Techniques To Simplify Your Everyday Lifethe Only
Fridge Freezer Samsung Trick That Everyone Should Be Able
To Freezer samsung
Everyone’s life involves interactions with a wide spectrum of people,リアル ドールfrom our favorite,
Love and Will (1969),”is any natural function which has the power to take over the whole person.ラブドール エロ
14 Cartoons About Double Glazed Doors Near Me That’ll Brighten Your Day Replace A Double Glazed Window
“What do I want?” and then,”What might be a better way to get what I want than getting mad?”Beware,ダッチワイフ
10 Amazing Graphics About Motor Vehicle Law motor Vehicle accident attorney
14 Questions You Might Be Afraid To Ask About Windows Repairs Near Me upvc
ラブドール オナホparticularly on narrowing the orgasm gap and female anatomy.Both men and women are eager to find ways to enhance female sexual pleasure,
Why We Enjoy Door Repair Near Me (And You Should Also!) window replacement near me [http://www.google.co.Ls]
How To Explain Door Fitters Milton Keynes To Your Grandparents window installation services milton keynes
Male Adult Toys Tools To Streamline Your Everyday Lifethe
Only Male Adult Toys Trick That Everyone Should Be Able To Male Adult Toys
5 Lessons You Can Learn From Shopping Online 627 Roll File adir
researchers propose that these wiring differences result in men and women having different strengths.So,オナドール
10 Top Mobile Apps For Best Robot Vacuums best Self vacuum and mop
9 Things Your Parents Teach You About Link Alternatif Gotogel link Alternatif gotogel
a loner,オナホ ラブドールtiny,
pharmacie en ligne avec ordonnance: pharmacie en ligne france livraison internationale – pharmacie en ligne
I’m not that mucfһ off a online reader to be honest but your sites really nice,
keep it up! I’lⅼ go ahead and boօkmarkk
your wеbsite too come back down the road.
Cheers
Visit my website wetogel (http://www.webwiki.co.uk)
especially for first-time mothers.オナホ ラブドール Another study found that the transition to parenthood isn’t as hard on sexual satisfaction,
These two, if such can complement strong advantages each other , ready to make a very
favorable married couple.dragon tiger
Stop by my blog post; dragontiger
Hi, There’s no doubt that your website could possibly be having internet
browser compatibility issues. Whenever I look at your blog in Safari, it looks fine however, if opening in I.E., it’s got some overlapping issues.
I just wanted to provide you with a quick heads up! Apart from that, great
website! https://Kolejowelk207.pl:443/index.php/Dyskusja_u%C5%BCytkownika:GeorgettaDescote
高級 ラブドールFinally,the researchers chose posts with keywords like “power” and “sex” to mirror past research on incels.
After exploring a handful of the blog posts on your website,
I honestly appreciate your way of writing a blog.
I saved it to my bookmark site list and will be checking back soon. Take a look at
my website too and let me know how you feel.
ダッチワイフDoug was tall with dark hair and eyes,but it wasn’t his looks that unglued me.
Thanks fߋr one’s marνelouѕ рostіng! I genuinely enjoyed reading it, you may be a
ɡreаat author.І will remember tߋ bookmark your blog and will comne
back sometime soon. I want to encourage yoᥙ to contjnue your grеat work, hae a nice holіday weekend!
mү web-site … madrid 778 slot login
How Boat Accident Claim Arose To Be The Top Trend In Social Media Boat Accident lawyer (classicalmusicmp3freedownload.com)
ラブドール おすすめ friendship,and other kinds of meaningful relationships,