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
In this case, the life insurance policy business’s cash.
Stop by my web site what does enable need decay mean
They have items to offer or services to use.
Also visit my blog … bookmarks
Medication information sheet. Brand names.
reglan cost
Actual what you want to know about medication. Read here.
plant based vape canada-based
vapes have a host of potential benefits.
Drug prescribing information. Drug Class.
dilantin without insurance
Best news about drugs. Get now.
can i purchase pregabalin without rx
9 . What Your Parents Taught You About Best Online
Clothing Sites Uk Best online clothing Sites uk
Kylian Mbappe is a French professional footballer who plays as a forward for Paris Saint-Germain and the French national team. Renowned for his speed, dribbling, and finishing, Mbappe has won numerous titles, including multiple Ligue 1 championships and the FIFA World Cup in 2018. Find out more about him here – https://kylianmbappe.paris-saint-germain-ar.com/
where to buy cheap cleocin without dr prescription
Upvc Door Repairs Near Me Tools To Ease Your Everyday Lifethe Only
Upvc Door Repairs Near Me Trick That Everyone Should Be Able To
upvc door repairs near me (Delila)
This web site definitely has all the information and facts I wanted
concerning this subject and didn’t know who to ask.
In this instance, the life insurance company’s loan.
Here is my site: Bookmarks
In this case, the life insurance policy firm’s cash.
Here is my web site – ai headshot generator free review
I would like to thank you for the efforts you’ve put in penning this website.
I am hoping to view the same high-grade blog posts by you in the
future as well. In truth, your creative writing abilities has encouraged me
to get my own, personal site now 😉
ฉันจำเป็นต้องบอกว่า
บทความนี้ให้ข้อมูลที่มีคุณประโยชน์มากมายเกี่ยวกับ คาสิโน
มารีน่าเบย์ สิงคโปร์!
ฉันเองเป็นคนอีกคนหนึ่งที่ชื่นชอบในด้านการเล่นเกมรวมทั้งพนันออนไลน์ เพราะเหตุว่ามันสะดวกและสามารถเล่นได้ทุกที่ที่ต้องการ ทั้งยังมีเกมให้เลือกมากมาย ตั้งแต่เข้าเกมสล็อต รูเล็ต ไปจนถึงโป๊กเกอร์ บล็อกนี้ช่วยให้ฉันเข้าใจถึงการเลือกเว็บไซต์คาสิโนออนไลน์เว็บตรงที่น่าไว้ใจ และการดูแลเรื่องความปลอดภัยสำหรับการเล่นเยอะขึ้นเรื่อยๆ ขอบพระคุณในการแบ่งปันข้อมูลดีๆอย่างงี้จ้ะ!
What is New U Life SOMADERM Transdermal Gel.
my webpage :: Bookmarks
See What Online Shopping Figures Uk Tricks The Celebs Are Using
Online Shopping Figures Uk
Find Out More About Who Repairs Sliding Patio Doors While Working From At Home window
Why Do So Many People Would Like To Learn More About Americanfridge Freezer?
Zack Foxworth
Cornbread Hemp CBD Gummies For Sale Gummies are USPS-friendly.
Also visit my web page – where can i find sex near me
Plant-based vapes have a host of possible advantages.
my webpage Bookmarks
Pills information leaflet. Cautions.
buy generic tetracycline pills
Some about medicament. Get here.
get cheap femara without insurance
оснащение конференц залов оснащение конференц залов .
Then You’ve Found Your Commercial Coffee Machines …
Now What? Essie
USP human development hormone (somatropin).
Feel free to visit my blog; motion animation online
Sexybaccaratthai.com คือปลายทางที่ดีที่สุดของคุณสำหรับเกมบาคาร่าออนไลน์ที่ดีที่สุด เพลิดเพลินไปกับการดำเนินการด้วยเงินจริงที่น่าตื่นเต้นและโบนัสมากมายเมื่อคุณเล่นในคาสิโนออนไลน์ที่ปลอดภัย เชื่อถือได้ และได้รับอนุญาตอย่างเต็มรูปแบบของเรา!
ลองของคุณ
My web-site: เกมคาสิโนออนไลน์ที่มีโบนัสและรางวัลแจ็กพอตมากที่สุด
Meds information. What side effects can this medication cause?
where to buy generic motrin pills
Best news about medicines. Get information here.
My coder is trying to convince me to move to .net from PHP.
I have always disliked the idea because of the expenses.
But he’s tryiong none the less. I’ve been using
WordPress on numerous websites for about a year and am worried about switching to another platform.
I have heard great things about blogengine.net. Is there a way I can import all my wordpress
posts into it? Any kind of help would be really
appreciated!
Feel free to visit my page genius wave reviews