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
Hi there very nice blog!! Guy .. Beautiful ..
Amazing .. I will bookmark your web site and take the feeds additionally?
I’m glad to search out a lot of helpful info here in the
submit, we want develop extra techniques in this regard,
thank you for sharing. . . . . .
Here is my page; testoprime
hepatitis c virus (hcv): online medicine shopping – naproxen pharmacy price
What To Do To Determine If You’re Prepared For Window Hinge Repairs Window hinges
You could certainly see your skills in the work you write. The arena hopes for even more passionate
writers such as you who aren’t afraid to mention how they believe.
At all times follow your heart.
7 Simple Strategies To Completely Rocking Your Togel4d toto4d
[Moises]
What’s The Job Market For Lightweight 3 Wheel
Rollator With Seat Professionals Like? 3 Wheel Rollator With Seat
I was suggested this web site by my cousin. I’m not sure whether this post is written by him as nobody
else know such detailed about my problem. You’re incredible!
Thanks!
kamagra oral jelly: bestsellers – Dostinex
You’ll Never Guess This Suzuki Key Replacement’s Tricks
suzuki key replacement [Latonya]
Could Mobile Automobile Locksmith Be The Key For 2023’s Challenges?
automotive locksmiths in my area (https://clearcreek.a2hosted.com/Index.php?action=profile;u=77499)
This design іs incredible! Yoou defіnitely know
h᧐w to кeeρ a reader amused. Βetween your
wit and your videos, I was apmost moved to
start my own bloց (well, almost…HaHa!) Great job.
I redally enjoyed what you had to say, and more than that,
how you presented it. Tooo cool!
Here is my web page … text inmate
pharmacy loratadine: florida online pharmacy – advair pharmacy assistance program
vibramycin online pharmacy: online pharmacy lortab – lorazepam indian pharmacy
Nicely put, Kudos!
How To Create An Awesome Instagram Video About Cars Locksmith Near
Me Car Locksmith Nearby
konteyner fiyatları | Yazınızı okurken birçok yeni şey öğrendim. Teşekkür ederim!
The Greatest Sources Of Inspiration Of Robot Vacuum That Mops best robot for vacuum and mop
– Louie –
heb online pharmacy: pharmacy continuing education online – navarro pharmacy store locator
But since marijuana and cannabis-related products were made illegal
in the US in 1970, there has been a dearth of research about either
marijuana or CBD. And since cannabis is in the
early stages of legalization and regulation, there is a huge variety in the quality and dosage of products – risks associated with using
products that have not been vetted by the FDA. And in approving the first CBD-based drug, Epidiolex, last year the FDA expressed enthusiasm for the research boom that is sure to come, paired with stern words for the flood
of marketers of products claiming unsubstantiated health benefits.
Meanwhile, the FDA issued a statement making clear that
products that contain CBD – even if they are derived from legal,
commercial hemp – cannot claim to have therapeutic benefits or be sold as dietary supplements unless they have been approved by the FDA for that use.
While anecdotal evidence of the benefits of CBD is common,
there are risks associated with using these products, especially
in children. But popular use of CBD is blowing up with very
little research into its safety or its efficacy, especially in children. Without a CoA (Certificate of Analysis) it’s that much harder to verify
the safety of the product.
I’m not sure exactly why but this blog is loading incredibly slow
for me. Is anyone else having this problem or is
it a problem on my end? I’ll check back later on and see if the problem still exists.
Ԝhat’s up, its ɡood article гegarding media print, we alⅼ be familiar
ѡith media iis a impressive source οf data.
Ⅿy site; situs slot terbaru
You’ll Never Guess This Electric Treadmill Folding’s Tricks electric treadmill folding
After I initially left a comment I appear to have clicked the -Notify me
when new comments are added- checkbox and from now on whenever a
comment is added I get four emails with the same comment.
There has to be an easy method you are able to remove me from
that service? Cheers!
9 Lessons Your Parents Taught You About Managing ADHD Without Medication managing adhd without medication (https://buketik39.ru/user/parrotrod2)
online pharmacy clonidine: Retrovir – rx pharmacy shop coupon code
Magnificent beat ! I wish to apprentice whilst you amend your web site, how can i subscribe for a blog site?
The account helped me a applicable deal. I were tiny bit acquainted
of this your broadcast provided vivid transparent concept
Advair Diskus: health rx pharmacy – femara online pharmacy
hello there and thank you for your info – I have certainly picked up anything new from right here.
I did however expertise several technical points using this
web site, as I experienced to reload the website
a lot of times previous to I could get it to load properly.
I had been wondering if your web hosting is OK?
Not that I’m complaining, but sluggish loading instances times
will very frequently affect your placement in google and could damage your quality score if advertising and marketing with Adwords.
Anyway I’m adding this RSS to my email and can look out for a
lot more of your respective fascinating content. Ensure that you update this again soon.
Looking Into The Future What Is The Small Folding Wheelchair
Industry Look Like In 10 Years? easy folding wheelchair (Sheryl)
Ten Taboos About Automatic Fold Up Mobility Scooter You Should Not Share On Twitter automatic fold up scooter