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
вывод из запоя https://rio16.ukrbb.net/viewtopic.php?f=3&t=1121/ .
mexico pharmacies prescription drugs mexicanpharmeasy.com п»їbest mexican online pharmacies
best india pharmacy: indian pharm star – india pharmacy mail order
Do you mind if I quote a few of your articles as long as I provide credit and
sources back to your site? My blog is in the exact same area of interest as yours
and my visitors would truly benefit from a lot of the information you present here.
Please let me know if this alright with you.
Thank you!
This design is incredible! You obviously know how to keep a reader entertained.
Between your wit and your videos, I was almost moved to start my
own blog (well, almost…HaHa!) Fantastic job.
I really enjoyed what you had to say, and more than that,
how you presented it. Too cool!
natural ed remedies https://mexicanpharmeasy.com/# mexican drugstore online
Thanks for highlighting the importance of good screens! My go-to source is always Cape Coral Pool Cage Screen Repair for repairs
mexican mail order pharmacies Pharm Easy mexico drug stores pharmacies
Not everybody can afford medicine so they get the low is amlodipine an ace inhibitor at the lowest price possible
5 Killer Quora Answers On Anal Toys Price Uk Anal Toy
I have read so many content about the blogger lovers but this
article is actually a fastidious paragraph, keep it up.
india online pharmacy: indian pharm – india online pharmacy
п»їbest mexican online pharmacies: Pharm Easy – medicine in mexico pharmacies
вывод из запоя на дому в екатеринбурге https://www.uaportal.ukrbb.net/viewtopic.php?f=2&t=3722 .
I am sure this piece of writing has touched all the internet viewers,
its really really good piece of writing on building up new web site.
I really like your blog.. very nice colors & theme. Did you
create this website yourself or did you hire someone to do
it for you? Plz answer back as I’m looking to design my own blog and would like to find out where u got
this from. thanks a lot
mexico drug stores pharmacies MexicanPharmEasy reputable mexican pharmacies online
Hi! Do you know if they make any plugins to protect
against hackers? I’m kinda paranoid about losing everything I’ve worked hard on. Any
suggestions?
ed meds online https://indianpharmstar.com/# indian pharmacy paypal
Online medicine order indian pharm pharmacy website india
Address Collection: 11 Things You’re Forgetting To Do 링크모음
выведение из запоя https://www.tatuheart.ukrbb.net/viewtopic.php?f=8&t=15078 .
With havin so much written content do you ever run into
any issues of plagorism or copyright infringement?
My blog has a lot of completely unique content I’ve either written myself or outsourced but it appears a lot of it is
popping it up all over the internet without my agreement.
Do you know any techniques to help reduce content from being stolen? I’d certainly appreciate it.
To challenge someone is to dare someone
Michael schumacher. Garter snake. Hellboy 2004. Wal mart. Amazn. Stroopwafel. Edward norton. Proposition. Brendan gleeson. Pr. Vanilla. Glenn close. Swordfish. Poignant meaning. Taekwondo. Incompetent. The incredible hulk. Budapest. Kebab. Little rock. Sigourney weaver. Function. Cordial. Nostradamus 2024 predictions in english. Map of the us. Flat earth. Phil jackson. Red movie. Is juneteenth a federal holiday. Mossad. Generation x. Inevitable. Mbs. Deposit. Corpse flower. Nick lachey. Nafta. Columbian exchange. Houdini. Canoe. St. louis cardinals vs dodgers match player stats. Ludacris. Point reyes. Colombia. Zodiac sign dates. Presumed innocent. Full house cast. Fergie. Ladybug. Bagel. https://x5.yxoo.ru/
Ars. Review. Olivia colman. Groucho marx. Steroids. 20/20. Guggenheim museum. Acquaintance. Mitochondrion. Andy samberg. Ginza. Party animals. College board. John mayer. Date today. Lovejoy. Calligraphy alphabet. Pony. Style. Fa. Kitten. Emma thompson. Barbell. Barclays center. Beaumont. Madeira. Nicki minaj. Paradise lost. Rick riordan. Sao paulo. Favorite. South. Playstation 4. Choir. Sebastian stan. Senate. Lawrence taylor. Sugar cane. Maga. Zorro. Cyndi lauper. Tcl chinese theatre. Dignity. Hair. What is culture. A bug’s life. Rue. Kenny chesney.
pharmacies in mexico that ship to usa: MexicanPharmEasy – mexican pharmaceuticals online
вывод из запоя дома http://sait.anihub.me/viewtopic.php?id=5681/ .
ed meds online without doctor prescription https://mexicanpharmeasy.com/# mexican rx online
I’m digging the concept of textured rugs– it includes depth without being overwhelming!” # # anyKeyWord # flooring near me
Процесс получения диплома стоматолога: реально ли это сделать быстро?