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
denemebonusuverensiteler25: deneme bonusu veren siteler yeni – deneme bonusu veren yeni siteler
sweet bonanza: sweet bonanza – sweet bonanza
Эта цитата подчеркивает уникальность и гибкость игрового опыта в PUBG, где игроки могут влиять на исход событий и создавать свои собственные игровые истории.
sweet bonanza sweet bonanza kazanma saatleri sweet bonanza slot
Легальная покупка диплома ВУЗа с сокращенной программой обучения
deneme bonusu veren siteler: deneme bonusu veren yeni siteler – deneme bonusu veren yeni siteler
Dealing With Pranksters With Reverse Phone Search 다바오포커
What’s Happening i’m new to this, I stumbled upon this I have
discovered It positively helpful and it has aided me
out loads. I am hoping to contribute & assist different customers
like its aided me. Great job.
Valuable information! Find more at sprinkler repair contractor
yeni deneme bonusu veren siteler yat?r?ms?z deneme bonusu veren siteler yeni deneme bonusu veren siteler
The 10 Scariest Things About Refrigerated Containers
refrigerated containers (https://imoodle.win/wiki/the_evolution_of_biomass_boiler_housings_containers)
На сайтах об азартных играх еще не начали публиковаться рецензии,
а пользователи не успели
оставить отзывы и поделиться впечатлениями.
sweet bonanza oyna sweet bonanza sweet bonanza demo oyna
I know this if off topic but I’m looking into starting my
own blog and was curious what all is required to get setup?
I’m assuming having a blog like yours would cost a pretty penny?
I’m not very web smart so I’m not 100% sure. Any suggestions
or advice would be greatly appreciated. Thank you
Hello, after reading this amazing post i am as well delighted to
share my know-how here with friends.
navigate to this site https://www.vuoksenkalastuspuisto.com/2024/06/13/keberuntungan-besar-di-slot-hoki-88-rahasia-menang-yang-perlu-anda-tahu/
This is highly informative. Check out Agence SEO for more
I enjoyed this article. Check out عمل prk for more
I admire how thorough and detailed your posts are.
Приобретение диплома ВУЗа с сокращенной программой обучения в Москве
I observed your insights on emergency locksmith facilities truly powerful! Thanks for sharing! commercial locksmith
After seeing how stunning paver stones look in my neighbor’s yard, I’m convinced I need to redo mine! For inspiration and guidance, you should definitely see what’s available at low maintenance landscape
yat?r?ms?z deneme bonusu veren siteler yeni deneme bonusu veren siteler deneme bonusu veren siteler yeni
Thanks for finally writing about > JS 依照元素出現數量排序 – 馬老師 雲端研究室
< Loved it!
Appreciate the useful tips. For more, visit bed bug exterminator
Celebrating A 40Th Birthday – Party Ideas 아이러브밤 (Jennie)
Greate pieces. Keep posting such kind of information on Sell Your Motorcycle page.
Im really impressed by it.
Hi there, You have performed an incredible job. I’ll
definitely digg it and personally suggest to my friends. I
am sure they will be benefited from this website.
The Advantages Of Playing Poker On-Line 에볼루션 영화
deneme bonusu veren yeni siteler yeni deneme bonusu veren siteler deneme bonusu veren yeni siteler
denemebonusuverensiteler25: yeni deneme bonusu veren siteler – denemebonusuverensiteler25