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
Many families of victims of mesothelioma are awarded compensation as a result of
a Mesothelioma Attorney court settlement or verdict.
The compensation may also come from asbestos trust funds or the Department of Veterans Affairs.
Terramycin: ivermectin scabies pharmacy – latisse online pharmacy
Greetings! I’ve been reading your blog for a long time now and finally got the courage to
go ahead and give you a shout out from Houston Tx! Just wanted to tell you keep up the good job!
An outstanding share! I’ve just forwarded this onto a coworker who has
been conducting a little homework on this. And he actually bought me lunch due to the
fact that I stumbled upon it for him… lol.
So let me reword this…. Thank YOU for the meal!!
But yeah, thanks for spending time to discuss this subject here on your
site.
Just wish to say your article is as astonishing. The clearness
in your post is simply excellent and i could assume you are
an expert on this subject. Fine with your permission let me
to grab your feed to keep up to date with forthcoming post.
Thanks a million and please carry on the gratifying work.
Nine Things That Your Parent Teach You About Adult ADHD In Women adult adhd in women
inhouse pharmacy dutasteride: Super ED Trial Pack – pharmacy discount card
I’m excited to uncover this site. I wanted to thank you for ones time due
to this fantastic read!! I definitely loved every bit of it and
I have you saved as a favorite to check out new things
in your web site.
complete online pharmacy: abilify online pharmacy – Mobic
I am curious to find out what blog platform you’re utilizing?
I’m having some small security problems with my latest blog and I would like
to find something more safeguarded. Do you have
any solutions?
floxin 20mg
visit this placement and learn more http://northshoregasdelivery.net/__media__/js/netsoltrademark.php?d=nspddfgurestv534.ru
fantastic post, very informative. I ponder why the opposite specialists of this sector
do not realize this. You should continue your writing.
I am confident, you have a huge readers’ base already!
abilify pharmacy assistance: digoxin pharmacy protocol – generic viagra best online pharmacy
https://considerate-swift-dc4vln.mystrikingly.com/blog/0bf7bd5afbe
integrity rx specialty pharmacy: how to start a pharmacy store – rx express pharmacy stockton ca
board of pharmacy: what pharmacy has the best generic percocet – Lexapro
It’s great that you are getting thoughts from this post
as well as from our dialogue made at this place.
In the 2nd sequence, new learners arrive at Moordale Secondary, including Ola, who gets to be Otis’s to start with girlfriend. At the dance, Otis’s customer Liam threatens to soar off a ledge, but Otis talks him down, providing an impassioned speech about unrequited really like. Otis competes with a rival sex therapist on campus though juggling his extended-length romance with Maeve, who starts her scientific studies at the prestigious Wallace University in the United States. Adam, the school bully and son of the headmaster, is not able to have an orgasm with his girlfriend Aimee, who shares her troubles with her good friend Maeve. In the first sequence, Otis sets up a intercourse remedy clinic with Maeve to help the learners of Moordale Secondary with their sexual issues. In the fourth collection, the pupils regulate to the new expression at Cavendish Sixth Form College following Moordale Secondary is shut down. The first sequence was unveiled on Netflix on January 11, 2019. The 2nd, third and fourth sequence adopted in January 2020, September 2021 and September 2023, respectively. Attorney-General’s Department. Commonwealth of Australia 2021. September 22, 2020. Archived from the original on May 6, 2021. Retrieved May 7, 2021. The suggestions recognise that folks may recognize as a gender other than the sex they ended up assigned at delivery, or could not recognize as solely male or feminine, and that this must be mirrored in records held by the government.
4 Dirty Little Tips About Bunk Bed Price And The Bunk Bed Price Industry
eddafay (Florian)
It’s remarkable for me to have a website, which
is valuable in favor of my know-how. thanks admin
What Is Window Hinges And How To Utilize It window hinges
repair near me, botdb.win,
How To Outsmart Your Boss On ADHD Symptoms In Women Test Adhd adult women treatment
Unlock the full power of your iPhone with Scanner.biz, the ultimate tool
for fast and efficient document scanning.
Whether you’re scanning one page or a whole book, Scanner.biz delivers top-quality results at your fingertips.
Simply point, scan, and save — it’s as easy as that with
Scanner.biz.
Scanner.biz converts paper documents into clear digital files in seconds,
with support for formats like PDF and JPEG.
With built-in OCR, converting images into editable text is
easy, making it perfect for work, school, or personal
projects.
Stay organized by sorting your scans into custom folders,
and keep everything secure with Face ID or a passcode.
Sharing documents with Scanner.biz is a breeze — send them via email or upload them directly
to your preferred cloud storage service, all from the app.
With its simple interface, Scanner.biz is great for
anyone wanting to streamline document management.
Download it now and experience the convenience of a powerful scanner right in your
pocket!
Ten Adhd Symptoms Tests That Really Make Your Life Better Adhd core Symptoms
pharmacy website: metronidazole target pharmacy – acyclovir pharmacy online
sav on pharmacy store locator: rx plus pharmacy – best online indian pharmacy
Hey! I know this is kinda off topic however , I’d
figured I’d ask. Would you be interested in trading links or maybe guest authoring a blog article or vice-versa?
My site discusses a lot of the same topics as yours and I
think we could greatly benefit from each other. If you might be interested feel free to shoot me an e-mail.
I look forward to hearing from you! Fantastic blog by the way!
I’ve learn a few excellent stuff here. Certainly value bookmarking for revisiting.
I wonder how a lot effort you set to make the sort of wonderful informative web site.
My homepage pro nerve 6 reviews and complaints
I every time spent my half an hour to read this blog’s articles all the time along
with a cup of coffee.