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
buying amoxicillin online: Amox Star – order amoxicillin no prescription
Процесс верификации в Пин ап казино может
длится от пары-тройки часов до нескольких
дней зависимо от правильности предоставленных.
Here is my webpage бк мостбет
prednisone cream rx PredniBest prednisone capsules
darknet search engine tor markets 2024 darknet sites
Легальная покупка школьного аттестата с упрощенной программой обучения
Стоимость дипломов высшего и среднего образования и процесс их получения
There’s Enough! 15 Things About Capsule Machine Coffee We’re Sick Of Hearing capsule coffee maker
Сколько стоит диплом высшего и среднего образования и как его получить?
Wow 27438 auto glass
Покупка школьного аттестата с упрощенной программой: что важно знать
Keep this going please, great job!
смотреть фильмы онлайн бесплатно без регистрации
This piece of writing will help the internet visitors for setting up new blog
or even a blog from start to end.
Generally I do not read post on blogs, however I would like to say that this write-up very compelled me to take a look at and do so!
Your writing taste has been surprised me.
Thanks, very nice post.
prednisone 50 mg tablet cost prednisone without prescription where to get prednisone
You need to take part in a contest for one of the best blogs on the web.
I most certainly will recommend this blog!
Woah! I’m really digging the template/theme of this blog. It’s simple, yet effective. A lot of times it’s difficult to get that “perfect balance” between user friendliness and appearance. I must say that you’ve done a superb job with this. Additionally, the blog loads extremely fast for me on Internet explorer. Superb Blog!
An article worth your time—thought you’d like it http://koex21.co.kr/bbs/board.php?bo_table=free&wr_id=215730
Как не попасть впросак при покупке диплома колледжа или ПТУ в России
After looking at a number of the blog articles on your blog, I really like your
technique of blogging. I book-marked it to
my bookmark webpage list and will be checking back in the near future.
Take a look at my website as well and let me know your opinion. https://nlifelab.org/bbs/board.php?bo_table=free&wr_id=963882
Your insights are incredibly helpful—working with an effective # online marketing for lawyers # could transform our client
continue reading this https://philosophyandscienceofself-control.com/2024/06/13/misteri-di-balik-maxim-slot-mengungkap-rahasia-mesin-judi-terpopuler/
When choosing a new personalized birthday present for your spouse, think beyond typical presents and give attention to creating meaningful experience. A custom piece, engraved with the special date or even message, combines beauty with sentiment, while a tailored piece of art that will reflects a ram gives a deeply individual touch.
For the even more interactive gift, look at a curated scrapbooking or photo recording that highlights milestones inside your relationship. On the other hand, custom-made home personal, for example a personalized baby blanket or family brand sign, offers the two practicality and emotional value.
https://techbullion.com/9-meaningful-personalized-birthday-gifts-for-your-spouse/
If your current spouse enjoys a great unique experience, look at planning a delight getaway or the personalized adventure time. These thoughtful, custom-made gifts strengthen your connection and create sustained memories, showing your partner how well an individual truly know and even appreciate them.
The 10 Scariest Things About Best Delonghi Coffee Machine best Delonghi coffee Machine
Пошаговая инструкция по официальной покупке диплома о высшем образовании
Greetings from Ohio! I’m bored at work so I decided to check out your blog on my iphone during lunch break.
I love the knowledge you provide here and can’t wait to take a look when I get home.
I’m surprised at how fast your blog loaded on my mobile ..
I’m not even using WIFI, just 3G .. Anyways, superb site!
Feel free to visit my web blog – specialized Alzheimer’s care
buy cipro without rx: ci pharm delivery – cipro pharmacy
Узнайте, как приобрести диплом о высшем образовании без рисков
Unexpected Business Strategies For Business That Aided
Drip Coffee Pot Succeed drip coffee equipment [Emelia]
Приобретение диплома ПТУ с сокращенной программой обучения в Москве
What an enlightening read about using chiropractic care as part of recovery from car accidents; very encouraging for victims like me! Chiropractic treatment for whiplash and neck pain