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
http://slotsiteleri.bid/# slot kumar siteleri
You’ll Never Be Able To Figure Out This Small Treadmill With Incline’s Tricks Small treadmill with incline
Oil Filled Radiator Timer Tools To Ease Your Everyday Lifethe Only Oil Filled Radiator Timer Trick That Everyone Should Know oil Filled radiator timer (http://woori033.kr)
Terrific post however I was wanting to know
if you could write a litte more on this topic?
I’d be very grateful if you could elaborate a little bit further.
Bless you!
What’s The Job Market For Robot Vacuum Bagless Self Emptying Professionals Like?
robot vacuum bagless self Emptying
deneme bonusu veren siteler: oyun siteleri slot – deneme bonusu veren siteler
guvenilir slot siteleri: slot bahis siteleri – en guvenilir slot siteleri
смотреть фильм
InstaSlim capsule helps to burn down calories and it works
intensively within the body. In brief, in the course of the digestion course of, our our bodies burn calories.
Tons of obese individuals who would do anything to burn fat at
a pace faster than that of a rocket need not do something of
stranger sort. Individuals who read frequently are less likely to undergo from depression and anxiety.
Your proper decision can take you on the top of this world and one other
failure may deliver you near the darkness of depression. Let’s take a quick check out merely what’s metabolism and how does it works.
Learn the details at How Vitamin D Works. 4. 35% of adults aged above 20 had been overweight in 2008 and 11% have been obese too.
5. In 2008, greater than 1.Four billion adults who aged from 20 and
above had been overweight. What are these individuals supposed
to do who don’t fall underneath normal weight category.
The task of discovering right type of complement can flip to be
a turning level of those lives who have been figuring out desperately to lose
some pounds of weight.
Ten Things You’ve Learned In Kindergarden That Will Help You Get
Woodburners Woodburning Stoves
สาระ ของบล็อกนี้น่าสนใจ มากๆ
ครับ ผมชอบวิธีการ ตรวจสอบ ประเด็นต่างๆ อย่าง รอบคอบ และ มีความเป็นเหตุเป็นผล ชัดเจน เป็นการช่วยให้ผู้อ่าน
ทำให้เข้าใจประเด็นได้ อย่างถ่องแท้มากขึ้น คุณเขียนได้อย่าง เป็นลำดับ และ น่าเอาใจใส่ซึ่งเป็นสิ่งสำคัญสำหรับบทความระดับนี้
นอกจากนั้น ผมยังชอบ ทัศนะ ใหม่ๆ
ที่คุณได้นำเสนอ ซึ่งเป็นสิ่งที่ ยังไม่เคย คิดมาก่อน มันช่วยขยายวิสัยทัศน์
และ ความรู้ ของผมไปในทิศทางที่ ขยายขอบเขตขึ้น
ผมขอขอบคุณที่คุณได้ แชร์ ความรู้และ ความเชี่ยวชาญ ของคุณ มันช่วยให้ผมได้
พัฒนาตัวเอง มากขึ้นอย่างแน่นอน
ผมหวังว่าจะได้ ติดตาม บทความอื่นๆ
ของคุณในอนาคตเช่นกัน เพราะผมมั่นใจว่าจะมีประโยชน์ และเป็นการเพิ่มพูน ความรู้ให้กับผมอย่างแน่นอน ขอบคุณมากครับ!
Also visit my site – สล็อตออนไลน์ (maps.google.gg)
Guide To Walking Pad Standing Desk: The Intermediate
Guide For Walking Pad Standing Desk walking pad standing desk (Leandro)
5 Best Car Seats Lessons Learned From The Professionals best Car Seats For newborns
Five Essential Qualities Customers Are Searching For In Every Ford Keys
Cut ford focus Car key replacement
You’ll Never Guess This Treadmill For Sale’s Secrets
treadmill for sale
An outstanding share! I’ve just forwarded this onto
a coworker who has been conducting a little homework on this.
And he actually bought me lunch due to the fact that I discovered it
for him… lol. So allow me to reword this….
Thank YOU for the meal!! But yeah, thanx for spending time to discuss this matter here on your internet site.
The 10 Scariest Things About Robot Vacuum With Self
Emptying robot Vacuum with self empty
http://slotsiteleri.bid/# en iyi slot siteler
10 Things We All Love About Defra Wood Burning Stoves Buy DEFRA stoves
canl? slot siteleri: slot casino siteleri – canl? slot siteleri
I do not even understand how I finished up here,
however I believed this submit was good. I do not know who you
might be however definitely you are going to a famous
blogger in the event you are not already. Cheers!
What’s The Current Job Market For Cheapest Folding Mobility Scooter Professionals Like?
cheapest Folding mobility scooter
Tips clearly taken.!
How Much Can Auto Accident Attorney For Hire Experts Earn? auto accident attorney in Nyc
Adhd Symptoms Tools To Improve Your Life Everyday symptoms Of adhd
lesbian porn
Hey! Quick question that’s completely off topic.
Do you know how to make your site mobile friendly?
My weblog looks weird when browsing from my iphone4.
I’m trying to find a template or plugin that might be able to resolve this problem.
If you have any suggestions, please share. With thanks!
https://slotsiteleri.bid/# guvenilir slot siteleri 2024
hacklink
https://sweetbonanza.network/# sweet bonanza slot