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
Ӏt’s peгfec timke tοo maake a feww plasns ffor tthe longer terгm aand
itt iis time tto bbe happy. I’ve rad tіs puut upp
aand iff I maay juset I wisѕh too reccommend yyou feew fascimating isesues orr advice.
Maаybe youu cann wrote suvsequent artices refeerring too thiis article.
I wan too larn evern mopre isses approximately it!
Feell freee too viisit myу sitеe – ورود به بهترین سایت
http://prednibest.com/# prednisone pill 20 mg
The significance of mental health in pain management can not be overstated. Integrative methods truly help resolve both physical and psychological well-being infrared neuropathy treatment
Интересные статьи о займах – https://rcmm.ru/press-relizy/55392-kak-sdelat-remont-esli-ne-hvataet-deneg.html
https://prednibest.com/# prednisone tablets india
вывод из запоя в санкт петербурге вывод из запоя в санкт петербурге .
After using bail bonds near me for our bail needs, I feel confident referring them to anyone else who might need help in Dallas
Simply wish to say your article is as astonishing.
The clarity to your put up is simply great and that i
can assume you are knowledgeable in this subject.
Well together with your permission allow me to seize your feed to
stay up to date with approaching post. Thank you one
million and please carry on the gratifying work.
purchase amoxicillin 500 mg amoxil generic 875 mg amoxicillin cost
Just got my air conditioning installed by a fantastic Richmond contractor from roof installation —highly recommend
http://clomidonpharm.com/# can i get clomid prices
For Sale: Database of Casino Players in Europe
Are you looking for a way to expand your customer base and increase your business revenue? We have a unique offer for you! We are selling an extensive database of casino players from Europe that will help you attract new clients and improve your marketing strategies.
What does the database include?
• Information on thousands of active casino players, including their preferences, gaming habits, and contact details.
• Data on visit frequency and betting amounts.
• The ability to segment by various criteria for more precise targeting.
The total database contains 2 million players. Data is from 2023. The database is active, and no mailings have been conducted yet.
The price for the entire database is 5000 USDT.
The price for 1 GEO is 700 USDT.
Tier 1 countries.
For any details, please contact me:
Telegram: https://t.me/Cybermoney77
Thanks for shedding light on the importance of utilizing the right chemicals in soft cleaning– extremely helpful checked out https://files.fm/u/5h6c9j6spb
Thanks for finally talking about > JS 依照元素出現數量排序 – 馬老師 雲端研究室 < Loved it!
prednisone 60 mg daily: order prednisone 10mg – how much is prednisone 10mg
Thank you for some other informative web site. The place else may just
I get that kind of info written in such an ideal way?
I have a mission that I’m simply now operating on, and I have
been on the look out for such info.
Howdy! Quick question that’s completely off topic.
Do you know how to make your site mobile friendly?
My web site looks weird when browsing from my
iphone4. I’m trying to find a template or plugin that might
be able to fix this problem. If you have any recommendations,
please share. Cheers! http://idesys.co.kr/bbs/board.php?bo_table=free&wr_id=51304
amoxicillin 500 tablet Amox Star amoxicillin 500mg price in canada
Hi i am kavin, its my first time to commenting anywhere, when i
read this paragraph i thought i could also create
comment due to this good article. https://vknigah.com/user/BennettGilley/
Hi there, after reading this remarkable post i am also happy to share my
know-how here with mates.
It’s excellent to see more awareness around home healthcare choices! Households should have to understand the very best ways to support their liked ones in your home. Explore resources at home health care agencies
15 Inspiring Facts About Treadmills The Words You’ve Never Learned treadmills At home
Knowing when to reach out to a best personal injury attorney could save you time and money down the road after an accident
Guide To Car Key Repairs Near Me: The Intermediate Guide On Car Key Repairs Near Me car Key repair
[https://bookmarkspot.win/]
Heya i’m for the first time here. I found this board and I in finding It truly helpful
& it helped me out much. I’m hoping to give something again and help others like you
aided me. http://Barunface.com/bbs/board.php?bo_table=free&wr_id=114191
On our website you will find a unique assortment rare coins from all over the world. We offer both modern and historical specimens that will become real finds for collectors.
For more information, follow the link [url=https://numizmatexpert.ru/]какие монеты ссср ценятся [/url]
Our team of experts carefully selects each coin, ensuring high quality.
Интересные статьи о займах – http://historic.ru/news/item/f00/s38/n0003807/index.shtml
Appreciate the useful tips. For more, visit facial plastic surgery
Как официально приобрести аттестат 11 класса с минимальными затратами времени