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
If you’re thinking about purchasing Penis enlargement Pump online enlarger pumps,
there are a few things to be aware of. First, ensure that the pump
is effective. Also, look up customer reviews, since some pumps will offer their customers a fee to write glowing
reviews.
Many people believe that they have average quick iq test Online scores,
and while this may be true, the actual results are more precise.
The majority of people fall in the upperand
lower margin intervals of the average range.
There are a lot of things to consider when cleaning your realsex dolls.
Particularly if they come with openings, they
require to be cleaned thoroughly. They should not be
cleaned using chemicals or bleach.
Also visit my webpage – Real dollsex
If you’re looking for a nourishing SPF 50 Moisturiser With Spf 50 then you’ve come to the right place.
Sunny Daze SPF50 Moisturizer provides both UVA and UVB protection, and is rich
in vitamin E and zinc oxide.
Hi to every single one, it’s in fact a good for me to go to see
this web page, it consists of helpful Information.
Before purchasing Delta 8 flower Near me eight flowers, consult
your physician. Certain medical conditions could be affected
by certain of these products. If you suffer from a medical condition or taking prescription medication, it is important to consult a doctor.
Excellent way of telling, and pleasant post to take facts regarding my presentation subject matter, which i am going to present in institution of higher education.
cbd dog oils For sale for dogs has numerous benefits.
These benefits are well-known and widely utilized. They are made from terpene-rich hemp plants and are safe for pets and humans alike.
Fans of sports in New York are allowed to place
bets online since Jan. 8th, 2022. Four major operators have obtained licenses for mobile betting which allows them
to offer their services in various ways. These operators
are Bally’s and DraftKings NY.
Also visit my blog – bet (Kerry)
The Dinner Lady CBD E-Liquid has been specifically designed for use by adults in the
UK. It has 1000mg Cbd Vape Juice Online and is produced in the UK
by a well-known brand with its headquarters in Greater
Manchester.
The ADHD Centre is home to an array of psychologists and ADHD
Behavioural Coaching Coaches. Its goal is to improve the study
of science and Adhd Clinic London, a
neurological condition that affects people throughout their lives.
Hi there i am kavin, its my first time to commenting anywhere, when i
read this paragraph i thought i could also create comment
due to this sensible article.
Look into my blog … Best onlyfans Twitter
If you have a desire to become a psychiatrist but aren’t covered
by insurance, you might want to think about the practice of psychiatry as a private psychiatry near me one.
When it comes to wall mounted fireplace electric options there are a variety of
options. You can choose from Napoleon Allure, Winslow, or
Prism. If you’re looking for more options, you can also opt for flicker lights.
Online psychiatric help can be an excellent method for professionals to
assist you. There are numerous advantages to getting your
care online.
There are many different rules and rules that govern online gambling.
For example, in the US you are not allowed to operate gambling sites that
are in your country of residence. However, it could be established elsewhere.
My blog – Live
If you have stuck keys in your car lock There are a variety of options available to you.
You could try to pull the key yourself, but this could
cause damage to your lock or your key. Thankfully, a
car key locksmith can assist you out of this dilemma.
CBD oil for cats is not a cure for medical conditions, but it can provide a variety of advantages.
When looking for Cbd Treats For Cats For Sale
products for cats, you must be aware of your cat’s individual needs and preferences.
There are numerous types of Wall Electric fire-mounted electric fireplaces therefore you must pick the one that’s right for you.
We’ll discuss the Moda Flame MFE5048WS as well as the Dimplex Synergy.
FLAME will provide an overview of what they can do with it.
I every time used to study piece of writing in news papers but now as I am a user of internet
thus from now I am using net for articles, thanks to web.
A folding foldable mobility Scooter scooter is a light alternative to a full-sized scooter that is simple to transport.
The folding scooters weigh less than larger models and are
shipped in between three and seven days.
you’re really a just right webmaster. The site loading speed is amazing.
It seems that you are doing any distinctive trick.
Also, The contents are masterpiece. you have performed
a fantastic task in this topic!
Feel free to visit my homepage – full psp game
uPVC windows in aluminium Doors Romford (porkshop.org)
are a fantastic choice for homes of all shapes and sizes.
The reasonable prices of these windows make
them a great choice for those on a budget. uPVC windows in Romford are also available in a
wide range of unique designs.
The Private adhd clinic London Centre has a team
of highly skilled therapists and consultants comprising psychologists and ADHD
Behavioural Coaches.
If you’re looking for more information on sash window repair
repairs, read this article. We’ll talk about the most frequently encountered issues, costs,
and requirements to draughtproof a window sash.
Bella Bumzy, Maria Moobs, Sunny and Emmy Beehz are all cult favorite among onlyfan models.
How do you pick the best ones? Here are some tips to aid you in making the best purchase.
There are many benefits when you have Transit Van Security Locks security locks installed on your
vehicle. You don’t need to spend money on the lock, as it can be put away.
If you’re frequently absent from your vehicle it can stop
thieves from opening it.
Misted-up double glazed window repairs near Me glazing is a temporary solution.
However, it is an affordable and simple way to improve the thermal efficiency of your home.
Here are some steps you can take.
There are numerous options when it comes to uPVC windows for sale in st albans windows And doors Albans.
These windows are perfect to improve the appearance of your home and assisting you reduce your heating expenses.
Two kinds of auto glass repairs that are commonly performed in French Doors st Albans Albans,
West Virginia are windshield replacement and repair. These issues
are usually caused by vandalism or accidents. The process
of replacing the glass is easy.