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://ozempic.art/# ozempic coupon
Guide To ADHD Test Adults: The Intermediate Guide In ADHD Test Adults Adhd Test Adults
cheapest rybelsus pills semaglutide cost semaglutide online
What Replace Land Rover Key Battery Experts Want You To Learn Land rover key replacement near Me
1xBet Slot Promo Code https://actuchomage.org/includes/wkl/code_promo_69.html
Promo codes for slots on 1xBet provide players with free spins or bonus funds to use on popular slot games. These codes are a great way to try out new slots or increase your chances of hitting a big win.
Take A Look At The Steve Jobs Of The Best Man Sex Toys Industry male adult Products
buy cheap ozempic buy cheap ozempic ozempic generic
Свой Психолог сейчас
нарколог на дом в краснодаре нарколог на дом в краснодаре .
What Is Sexdolls Realistic’s History? History Of Sexdolls Realistic ultra realistic love dolls [Julia]
The Ultimate Glossary Of Terms About Situs Toto Togel Bandar Toto
Guide To Folding Powered Wheelchair: The Intermediate Guide Towards Folding Powered Wheelchair
folding powered wheelchair (Kelley)
выезд нарколога на дом цена выезд нарколога на дом цена .
вывод из запоя цены ростов вывод из запоя цены ростов .
Guide To Daftar Akun Togel Resmi: The Intermediate Guide The Steps To Daftar Akun Togel Resmi daftar Akun togel resmi
вывод из запоя круглосуточно ростов-на-дону вывод из запоя круглосуточно ростов-на-дону .
Decide funding for the upcoming motor vehicle or refinance with self esteem.
Take a look at currently’s car financial loan costs.
Time for you to first payment: After you offer a product,
anticipate a wait duration of all-around 5 times to get money within your checking
account on most platforms.
There’s no justification for working away from money any more.
Nicely, many of us mess up in some cases, but there’s no purpose you shouldn’t be able
to conjure up a couple of hundred dollars away from slender air
for those who’re prepared to get Inventive regarding
how to make money.
Not everyone seems to be courageous adequate to hire out their total residence to
your stranger, but even leasing out the spare space can offer a large supply of
excess money. You may perhaps meet some attention-grabbing
individuals and find yourself enjoying it.
In the same way, if you’ve attained past success on the planet of entrepreneurialism,
your services could be of use to budding business people as well as established business
people who want to consider their organization to the subsequent amount.
Everybody knows that therapy is actually a hugely-expert and hard occupation, although not Lots of people realize it’s shifting online.
A different crucial element of promoting and advertising
is casino starting off a good email promoting system, which helps to keep customers and change prospects.
You may also make money fast by completing surveys, microtasks,
rewards plans, or any of the other simple tips on this checklist.
The quantity you’ll get won’t be high, but It’ll be quick.
In addition to supporting organizations to deal with their social accounts, you’ll be able to give them advice regarding
how to sort a protracted-expression social websites strategy.
Should you aren’t excited about working with a pc all day, Check out a lot of the finest
methods to make money offline:
Engaging in liable gambling with bonus resources and managing
them as authentic money can cause greater determination-making along with a
simpler reward system.
Choose in for bonus resources. As many as 50x wagering,
recreation contributions differ, max. stake applies, new
customers will have to decide in and claim offer in just 24
hrs and use inside thirty days. Geographical
Limits and T&Cs
I’m not sure if it’s intentional or an editorial remark, though the
pitch for blogging claims “Is there a topic or subject matter you’re really experienced about and luxuriate in adequate to have the ability to create on it
each day For some time?
That compensation impacts the location and buy
by which the manufacturers are offered and is some scenarios may impression the rating that may be assigned to them.
MONEY
FREE CASH
CASINO
PORN
SEX
ONLY FANS
Hello, I enjoy reading all of your post. I like to write
a little comment to support you.
erste hilfe kurs
Thanks a bunch for sharing this with all people you actually
recognize what you are speaking approximately! Bookmarked.
Please also discuss with my website =). We can have a
hyperlink trade arrangement between us
ozempic generic: ozempic generic – ozempic generic
Hi! I know this is kinda off topic however I’d figured I’d ask.
Would you be interested in exchanging links or maybe guest writing a blog post or vice-versa?
My blog addresses a lot of the same topics as yours and I believe we could greatly benefit
from each other. If you’re interested feel
free to shoot me an email. I look forward to hearing from you!
Superb blog by the way!
В магазине сейфов предлагают где купить сейф купить сейф интернете
https://rybelsus.shop/# semaglutide cost
Guide To Anxiety Disorder Separation: The Intermediate Guide On Anxiety Disorder Separation anxiety disorder separation
врач нарколог на дом платный врач нарколог на дом платный .
Thanks for sharing your thoughts on کفش لژدار طبی.
Regards
нарколог вывод из запоя ростов нарколог вывод из запоя ростов .
How To Create An Awesome Instagram Video About Treadmills Home Gym Treadmill Home Gym (https://Bookmarkextent.Com/Story17725720/From-The-Web-The-20-Most-Amazing-Infographics-About-Treadmills-For-Home)
How To Choose The Right Private Psychiatrist On The Internet private psychiatric assessment london (olderworkers.com.au)
buy viagra online