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
How To Know If You’re Ready To Go After Veterans Disability Lawsuit veterans disability law Firm
20 Trailblazers Lead The Way In Hades Gods Tier List
oscarreys.top
actos 30 mg
homosexual porn
mexican drugstore online
https://cmqpharma.online/# medicine in mexico pharmacies
mexican drugstore online
Here is my webpage: local hookups
Building Backlinks For Could 구글지니어스 [amarms.com]
medication from mexico pharmacy
http://cmqpharma.com/# п»їbest mexican online pharmacies
mexican pharmaceuticals online
Hi there! erection pills online beneficial website.
buying prescription drugs in mexico online
https://cmqpharma.online/# buying from online mexican pharmacy
buying prescription drugs in mexico
mexican border pharmacies shipping to usa
https://cmqpharma.com/# buying prescription drugs in mexico
purple pharmacy mexico price list
lgbt porn
Lorem Ipsum has been the industry’s standard dummy text https://amaterasuspa.pl/qrque of type and scrambled it to make a type specimen book.
You really make it appear really easy together with your presentation but I to find this topic to be
actually something which I think I might never
understand. It sort of feels too complex and very
wide for me. I am looking ahead to your subsequent publish, I’ll attempt to get the hang of it!
15 Best Pinterest Boards Of All Time About Car Key Fob Programming Near
Me 5611432.xyz
mexican rx online
https://cmqpharma.online/# pharmacies in mexico that ship to usa
mexico drug stores pharmacies
Roulette Suggestions For Beginners 프라그마틱 무료슬롯
I think what you typed was very logical. However, think about this, suppose you added a little information?
I ain’t saying your content is not good, but suppose you added
a post title that grabbed people’s attention? I mean JS 依照元素出現數量排序 – 馬老師 雲端研究室 is
a little plain. You ought to look at Yahoo’s home page and see how they write post titles to
get people to click. You might try adding a video or a related picture or two to grab people interested about everything’ve got to say.
In my opinion, it could bring your blog a little livelier.
mexican mail order pharmacies
http://cmqpharma.com/# pharmacies in mexico that ship to usa
mexico drug stores pharmacies
I do not even know how I ended up here, but I thought this post was great.
I don’t know who you are but certainly you’re going to a famous blogger if
you are not already 😉 Cheers!
mexican border pharmacies shipping to usa
http://cmqpharma.com/# mexico drug stores pharmacies
mexican rx online
how can i get differin
mexico pharmacies prescription drugs
http://cmqpharma.com/# mexico drug stores pharmacies
medication from mexico pharmacy
mexican mail order pharmacies
http://cmqpharma.com/# mexican rx online
purple pharmacy mexico price list
You’ll Never Be Able To Figure Out This Window Replacement Near Me’s Tricks Window Replacement Near Me
how to get advair diskus price
medicine in mexico pharmacies
http://cmqpharma.com/# mexican drugstore online
buying from online mexican pharmacy
Watch Out: How Wall Fireplace Electric Is Taking Over And What
To Do About It lynnbolvin.top
I could not resist commenting. Exceptionally well written!
I like reading a post that will make people think.
Also, thanks for permitting me to comment!