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
You’ll Never Guess This Trusted Online Shopping Sites For Clothes’s Secrets Trusted Online
Shopping Sites For Clothes; http://Web018.Dmonster.Kr/,
tamoxifen and ovarian cancer: aromatase inhibitor tamoxifen – tamoxifen buy
lisinopril pill 10mg lisinopril 5mg cost prices for lisinopril
10 Things You Learned In Kindergarden To Help You Get
Started With Window Replacement window replacement panes (Salvador)
I’m extremely impressed with your writing skills as well as with the layout on your weblog.
Is this a paid theme or did you modify it yourself? Anyway keep up the nice quality writing, it’s rare to see a nice blog like
this one today.
tamoxifen 20 mg nolvadex during cycle tamoxifen pill
Why You Should Concentrate On Improving Double Glazing Suppliers Near Me double Glazed windows near me (lovewiki.Faith)
10 Best Facebook Pages Of All Time About Pvc Window Repairs upvc Window repair
10 Graphics Inspirational About ADHD Adult Test adhd tests,
extension.Unimagdalena.edu.co,
lisinopril pill 40 mg: cheapest price for lisinopril – lisinopril online purchase
propecia without rx cost of generic propecia pills buying propecia price
purchase cytotec buy cytotec online fast delivery buy cytotec in usa
Whoa! This blog looks exactly like my old one!
It’s on a totally different topic but it has pretty much the same
page layout and design. Wonderful choice of colors!
lisinopril 20 mg discount lisinopril 240 lisinopril 2 mg
In the event you won’t keep in mind which knowledge incorporate paths that might require being
transformed, confirm the set up instructions for
every script/plan. Must you by no means have any databases, it’s possible you’ll skip these directions.
As such, any individual may manipulate, distribute, or in any
other case use the work, with out legal ramifications.
OneNote 2007 customers also can take part in a co-authoring session with OneNote 2010 customers if shared notebooks use the
older OneNote 2007 file format; nonetheless, co-creator search, and page versioning,
and compatibility with the OneNote Internet App will not be obtainable.
Make an observation of any particular chmod permissions you could have set on any file or folder (glimpse inside your FTP program’s help
recordsdata for details on checking a folder or file’s chmod permissions).
Check “Conserve as doc” and decide on possibly
“zipped” or “gzipped.” Click on “Go” and enable you
save the file (it could be a implausible strategy to construct a complete new folder
during which to avoid wasting a number of all of
your databases). In the event you actually don’t
have phpMyAdmin, you may be in a position to use this technique to create your databases.
King Ghidorah, with one final failed attempt made to make use of Kong in 2004’s Godzilla: Remaining Wars.
propecia generic: buying generic propecia online – buying generic propecia online
Content Marketing Consultant Tools To Streamline
Your Daily Lifethe One Content Marketing Consultant Trick
That Every Person Should Learn content marketing Consultant
See What Mental.Health Doctors Near Me Tricks The Celebs Are Making Use Of
Near Me
10 Double Glazed Window Repair Related Projects To Expand Your
Creativity window Repairs near me
15 Top Twitter Accounts To Learn About CS GO Weapon Case Operation breakout weapon case (https://rn.rnsh.net)
https://lisinopril.network/# buy zestoretic
https://natumbe.ru
My brother recommended I might like this website.
He was entirely right. This post truly made my day. You can not imagine simply how much
time I had spent for this info! Thanks!
Покердом имеет строгую политику, когда дело доходит до обработки запросов на депозит и вывод средств.
Редакция подготовила описание лучших новинок, а также предлагает опробовать автоматы в деморежиме.
what happens when you stop taking tamoxifen: liquid tamoxifen – tamoxifen for sale
Designer Handbags Beige Tools To Make Your Everyday Lifethe Only Designer Handbags Beige Trick That Every Person Should Learn designer handbags beige
I’m not sure where you are getting your information, but great topic.
I needs to spend some time learning much more or understanding more.
Thanks for fantastic information I was looking for this info for my mission.
See What Designer Handbags Brands Tricks The Celebs Are Utilizing Designer Handbags Brands
https://ciprofloxacin.tech/# buy cipro online without prescription
Если сумма выигрыша превышает 5 млн рублей, 1Win имеет право установить индивидуальный лимит на вывод в сутки. Мобильная версия и приложения. Для юзеров, предпочитающих мобильные гаджеты, у «1Вин» есть мобильная версия и приложения на iOS и Android 1win официальный