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
את הבחורה אתם יכולים לבחור מתוך הבחורות הנמצאות במקום, כך כל אחד יכול לבחור את הבחורה שמוצאת חן בעיניו ולבלות איתה. הבחורה תענג לאותם הרגעים שבהם אנשי עסקים רוצים לעשות משהו שונה בשביל לנקות את הראש. נערות הליווי יעניקו לאנשי העסקים חווית vip נעימה ומפתיעה סקס בבת ים
That is a good tip especially to those fresh to the blogosphere.
Short but very accurate info… Appreciate your sharing
this one. A must read post! https://bookmarkspecial.com/story17511280/%C3%89cole-esth%C3%A9tique
What’s The Current Job Market For Best Slot Machines Professionals Like?
classic slots (https://maps.Google.ml/)
A Provocative Rant About Classic Casino Slots modern Slots (coolpot.stream)
Hello! This is my 1st comment here so I just wanted to give a quick shout out and
say I genuinely enjoy reading through your blog posts.
Can you recommend any other blogs/websites/forums
that cover the same subjects? Thanks!
Right away I am going away to do my breakfast, when having my breakfast coming
yet again to read other news.
Five People You Need To Know In The Malpractice Attorneys Industry malpractice Law Firms
Medicines information for patients. Effects of Drug Abuse.
where can i get tetracycline without prescription
Everything about medicines. Get information here.
Your Family Will Thank You For Having This Uk Online Shopping Sites For Mobile Vimeo
9 Lessons Your Parents Taught You About Online Shopping Sites Clothes Cheap online shopping
sites clothes cheap (Ali)
See What Fela Railroad Tricks The Celebs Are Utilizing Fela Railroad,
https://Www.Alonegocio.Net.Br/,
10 Steps To Begin The Business Of Your Dream Double Glazed Units Near
Me Business Double Glased Doors (Canadianairsoft.Wiki)
deepthroat, blowjob, anal, amatureporn, facefuck, baldpussy, asstomouth, assfucking, bbw, bbc, bigcock, bigass, teenass, teenfuck, bigtits, titfuck,
footjob,thighjob, blackcock, hentai, ecchi, pedophliia, ebony, bigboobs,
throatfucking, hardcore, bdsm, oldandyoung, masturbation, milf,
missionary, nudist, oralsex, orgasm, penetration, pussylicking,
teenporn, threesome, whores, bokep, bokepindonesia, bokepterbaru, bokepindonesiaterbaru,
bokepterupdate, porno, pornoindonesia, pornoterbaru, pornoterupdate, xnxx.com, pornhub.com, xvideos.com, redtube.com
This excellent website definitely has all of the information I needed concerning this subject and didn’t know who to ask.
Railroad Injuries Lawyers Tools To Help You Manage Your Daily Life Railroad Injuries
Lawyers Technique Every Person Needs To Learn Railroad Injuries Lawyers
https://my-viagra-shop.ru/vliyanie-kofe-na-potenciyu.html
What Pram And Car Seat Could Be Your Next Big Obsession? Baby Travel
The 10 Most Terrifying Things About List Of Online Shopping Sites Uk List Of Online Shopping Sites Uk (2Ln.De)
Valuable posts Regards.
20 Things You Must Be Educated About Vegas Slots
Penny Slots
You made the point.
You’ll Never Guess This Upvc Windows And Doors’s Tricks Upvc Windows And Doors
You’ll Be Unable To Guess Patio Repair Near Me’s
Benefits patio repair near me (Will)
See What Slot Sugar Rush Demo Tricks The Celebs
Are Utilizing slot sugar rush Demo
12 Facts About Slot Updates To Make You Think About
The Other People Video slots
This is the right blog for everyone who really wants to
find out about this topic. You understand a whole lot
its almost hard to argue with you (not that I personally would want
to…HaHa). You definitely put a new spin on a
topic that’s been discussed for ages. Excellent stuff,
just great!
Medication information. What side effects?
effexor buy
Actual trends of medication. Read here.
הטובות ביותר מוכנות לפגוש כל חבר בכל יום לטיפולי עיסוי אירוטי בבאר שבע. התקשרו אליהן בלילה, וכל בחורה שאהבתם תיפגש איתכם. ניתן גברים הרוצים להתפנק עם עיסוי מרגיע ונעים יכולים לעשות זאת במספר מקומות. ניתן להזמין מעסות סקסיות כמעט לכל מקום כאשר האופציות נערות ליווי במרכז
How To Ship To Ireland From Uk Tips To Relax Your Everyday
Lifethe Only How To Ship To Ireland From Uk Trick That
Everyone Should Know How To Ship To Ireland From Uk – http://Divineleaders.Com
–
A Comprehensive Guide To Slot Strategies From Beginning To End Top developer slots, matkafasi.com,