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
mexican pharmaceuticals online: buying prescription drugs in mexico online – purple pharmacy mexico price list
reputable mexican pharmacies online: mexican pharmaceuticals online – mexico drug stores pharmacies
medicine in mexico pharmacies: mexico pharmacies prescription drugs – buying prescription drugs in mexico
The Most Significant Issue With Personal Injury Legal,
And How You Can Fix It personal injury lawsuit
https://filedn.eu/lXvDNJGJo3S0aUrNKUTnNkb/tendoncare23/research/tendoncare23-(183).html
Otherwise, photographs will appear off-balanced, and it may be misconstrued that one mom is trying to outshine or outdo the opposite.
shipping vehicle cross country shipping vehicle cross country .
Where Will Fridge Uk One Year From This Year? 36035372.Xyz
(http://Www.36035372.Xyz)
mexican pharmacy pharmacies in mexico that ship to usa buying prescription drugs in mexico online
L Shaped Kids Beds Tips To Relax Your Daily Lifethe One L Shaped Kids Beds Trick That Everyone Should Be Able To l shaped kids Bed
(tempaste.Com)
https://bogin2c.b-cdn.net/research/bogin2C-(110).html
This will assist her find the complementary ensemble and forestall her from being over or underdressed.
The 10 Most Terrifying Things About Classic Casino Slots classic casino Slots
buying from online mexican pharmacy: buying prescription drugs in mexico online – mexico pharmacies prescription drugs
https://seo15.z28.web.core.windows.net/research/seo15-(87).html
The safest bet is for the mother of the bride to put on a similar colour to the bridesmaids to remain on-theme.
https://digi6.b-cdn.net/research/digi6-(29).html
Plus, the silhouette of this robe will look that instead more show-stopping as the cape wafts down the aisle to reveal her silhouette as she moves.
Well spoken of course! .
Very great post. I simply stumbled upon your blog and
wanted to mention that I have truly enjoyed surfing around your
weblog posts. After all I will be subscribing on your rss feed and I am hoping you write again very soon!
https://bogin4.sfo2.digitaloceanspaces.com/research/bogin4-(91).html
The champagne coloured ankle-length wrap costume seems gorgeous on this mother of the bride.
mexico pharmacies prescription drugs: buying from online mexican pharmacy – medicine in mexico pharmacies
buying prescription drugs in mexico: mexican pharmaceuticals online – mexican border pharmacies shipping to usa
saya sangat suka child porn karena saya sangat horny setelah melihat nya, Jika kalian mau
melihat vagina anak-anak bisa bergabung disini
mexican border pharmacies shipping to usa: buying from online mexican pharmacy – п»їbest mexican online pharmacies
It’s A Glass Window Replacement Success Story You’ll Never Be Able To Replacement of window glass
10 Mobile Apps That Are The Best For Best Male Masturbation Toy best male masturbation toys
medication from mexico pharmacy: п»їbest mexican online pharmacies – reputable mexican pharmacies online
medication from mexico pharmacy: mexican pharmaceuticals online – pharmacies in mexico that ship to usa
Pills information sheet. Brand names.
get clozapine without prescription
All what you want to know about pills. Read information here.
A Comprehensive Guide To Inexpensive Sectional Couches.
Ultimate Guide To Inexpensive Sectional Couches Folding Couch Bed
The Reasons Coffee Maker Pod Is More Difficult Than You Think http://Www.822547.Xyz
You’ll Never Be Able To Figure Out This Winning Slots’s Tricks Winning Slots
pharmacies in mexico that ship to usa: buying from online mexican pharmacy – mexican pharmaceuticals online