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
У каждого слота есть демоверсия, кроме слотов PG Soft.
buy dapoxetine online: buy priligy max pharm – cheap priligy
A person necessarily lend a hand to make seriously articles I’d state.
This is the first time I frequented your web page and to this point?
I surprised with the analysis you made to make this actual submit incredible.
Wonderful activity!
my website :: Pinoy SEO Services
Medication information. Generic Name.
how to buy cheap loperamide tablets
Some what you want to know about pills. Read here.
stromectol 6 mg tablet: buy Stromectol – ivermectin 500ml
You expressed it well! http://images.google.com.mm/url?q=https://betflixauto.club
вывод из запоя круглосуточно краснодар на дому dolgoprudni.rusff.me/viewtopic.php?id=3065#p8958 .
вывод из запоя краснодар на дому familyportal.forumrom.com/viewtopic.php?id=28570#p70369 .
Узнай все о септопластика носасептопластика стоимость
Hello There. I found your blog using msn. This is an extremely well written article.
I’ll make sure to bookmark it and return to read more of your useful information. Thanks for the
post. I will definitely return.
вывод из запоя бесплатно http://www.aktivnoe.forum24.ru/?1-7-0-00012824-000-0-0-1730744727 .
вывод из запоя цена краснодар http://www.pelsh.forum24.ru/?1-8-0-00000126-000-0-0-1730745072/ .
Fantastic write ups, With thanks!
minocycline 50mg without doctor: buy minocycline 100mg otc – minocycline manufacturer
вывод из запоя в стационаре краснодара zavitai.mybb.social/viewtopic.php?id=90 .
вывод из запоя rodoslav.forum24.ru/?1-4-0-00000571-000-0-0-1730745118 .
lisinopril pills 2.5 mg: lisinopril1st – Lisinopril 1st
вывод из запоя краснодар http://nsk.ukrbb.net/viewtopic.php?f=45&t=29670/ .
вывод из запоя на дому в краснодаре http://chesskomi.borda.ru/?1-8-0-00003046-000-0-0-1730745020/ .
Узнай все о септопластика цена москвасептопластика носовой перегородки цена в москве
buy minocycline 50mg: generic Stromectol – buy minocycline 100 mg
I revealed your blog post to be a compelling and discerning examination of the present state of the sphere.
Your investigation of the key shifts and problems
addressing companies in this sector was outstandingly potent .
As an devoted advocate of this concern , I would be excited to further this conversation more thoroughly .
If you are inclined , I would happily implore you to explore
the captivating options open at WM CASINO.
Our system delivers a high-tech and secure landscape for interacting
with aligned enthusiasts and obtaining a profusion of tools to bolster your
comprehension of this fluctuating sector.
I anticipate the opportunity of partnering with you in the upcoming
future
My homepage: online casino
Полезные советы по безопасной покупке диплома о высшем образовании
darkweb marketplace darknet drug links https://darknetmarketstore.com/
Thanks for the marvelous posting! I definitely enjoyed
reading it, you may be a great author.I will ensure that I bookmark your blog and
will often come back down the road. I want to encourage one to continue
your great work, have a nice holiday weekend!
I am sure this post has touched all the internet users,
its really really nice piece of writing on building up new webpage.
Купить диплом магистра оказалось возможно, быстрое обучение и диплом на руки
Fantastic post however , I was wondering if you could
write a litte more on this subject? I’d be very grateful if you could elaborate a little bit further.
Bless you!
Официальная покупка аттестата о среднем образовании в Москве и других городах
buy Lisinopril online: Lisinopril 1st – lisinopril 20mg online