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
Great beat ! I would like to apprentice while you amend your web site, how could i
subscribe for a blog website? The account aided me a acceptable deal.
I had been a little bit acquainted of this your broadcast offered bright clear idea
вывод из запоя цены на дому ростов вывод из запоя цены на дому ростов .
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
15 . Things That Your Boss Would Like You To Know You’d Known About Small Espresso Machine uk espresso machine
https://ozempic.art/# ozempic coupon
10 Failing Answers To Common Window Hinge Repair
Near Me Questions Do You Know Which Answers? Window hinge repair costs
Не паблик Психолог сейчас
10 Inspirational Graphics About Wall Mount Electric Fireplaces white electric wall fire (Ina)
semaglutide cost semaglutide online buy rybelsus online
The 10 Most Scariest Things About Patio Sliding Door Repair Near Me patio sliding door repair near me
В магазине сейфов предлагают сейф сейф купить
What’s The Reason Private Psychiatrist Manchester Is Fast Increasing To Be The Hottest Trend Of 2023 private Psychiatrist Derby
https://ozempic.art/# ozempic online
Admiring the time and energy you put into your blog and detailed information you offer.
It’s nice to come across a blog every once in a while that isn’t
the same old rehashed information. Great read! I’ve bookmarked your site and I’m adding your RSS feeds to my Google account.
http://ozempic.art/# ozempic generic
В магазине сейфов предлагают сейф цена москва купить сейф
20 Resources To Help You Become More Successful At Freestanding Electric Fireplace Standing electric fires
вывод из запоя круглосуточно ростов на дону вывод из запоя круглосуточно ростов на дону .
Beware Of This Common Mistake You’re Using Your Key Replacement
For Car lost car keys replacement cost uk (Refugio)
What’s up i am kavin, its my first occasion to commenting anywhere,
when i read this post i thought i could also make comment due to this good piece of
writing.
Thanks designed for sharing such a pleasant idea, article
is pleasant, thats why i have read it entirely
https://ozempic.art/# ozempic online
10 Things You Learned From Kindergarden To Help You Get Started With Treating ADD In Adults can adhd get worse if untreated; mollerup-connor.thoughtlanes.net,
В магазине сейфов предлагают купить сейф в москве в магазине сейфов заказать сейф
5 People You Should Meet In The Panty Vibrators Online Industry women s vibrators (olderworkers.com.au)
https://rybelsus.shop/# buy semaglutide pills
В магазине сейфов предлагают можно купить сейф где купить сейф
rybelsus cost buy semaglutide online rybelsus price
Диплом пту купить официально с упрощенным обучением в Москве
спрос на них приводит к тому, что какие-то из них становятся платными.
Here is my website; https://ramblermails.com/