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
http://ozempic.art/# buy ozempic pills online
Awesome article.
Five Killer Quora Answers On 3 Wheel Stroller Cheap 3 wheel stroller cheap
(Sherry)
Xəbərdarlıq: you have to present you meet all age and other regulatory requireds before entering
a Mosbet
or placing a wager.
12 Companies Are Leading The Way In Replacing A Upvc Window
Handle replacement upvc window handles uk
ozempic generic: ozempic – ozempic cost
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
20 Trailblazers Setting The Standard In Nissan Qashqai Key Replacement Price nissan remote key
https://ozempic.art/# ozempic cost
ozempic coupon ozempic Ozempic without insurance
ozempic: buy cheap ozempic – buy ozempic
https://rybelsus.shop/# buy rybelsus online
The Complete Guide To Upvc Window Repairs Upvc Window Repairs Near Me
Greetings! Very helpful advice within this article! It’s the little changes that produce the most significant changes.
Thanks for sharing!
buy rybelsus online: semaglutide cost – rybelsus price
semaglutide cost semaglutide tablets semaglutide tablets
https://ozempic.art/# ozempic generic
I pay a visit day-to-day some blogs and sites to
read articles, however this website provides quality based posts.
buy ozempic pills online buy ozempic pills online ozempic cost
betting sites offers: Promo codes that provide free bets, allowing users to place wagers without using their own funds. These codes are often part of special promotions or sign-up offers.
A Guide To Door Fitting Bedford In 2023 picture window repair
semaglutide online rybelsus coupon buy rybelsus online
https://ozempic.art/# ozempic coupon
We’re a gaggle of volunteers and opening a brand new
scheme in our community. Your site offered us with useful
information to work on. You have performed a formidable task and our entire group will be grateful to you.
https://rybelsus.shop/# rybelsus coupon
https://ozempic.art/# ozempic cost
It’s nearly impossible to find educated people about this
topic, however, you sound like you know what you’re talking
about! Thanks
I every time emailed this web site post page to all
my friends, since if like to read it afterward my friends will too.
10 Amazing Graphics About Replacement Window Handle upvc replacement window handles
Five Killer Quora Answers To Wall Electric Fireplace Wall Electric Fireplace