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
It is not possible to tell by simply looking at something if it is made up of asbestos.
Also, you cannot smell or taste it. It is only found when the asbestos attorney-containing materials
are drilled, chipped or broken.
A claim for asbestos compensation is a claim
to receive financial compensation from the business or companies that
are responsible for asbestos exposure.
The Danube- Important change system consists of a total of three lakes, including the Altmühlsee with a ring dam and two
dams with Brombach and Rothsee, which include 5 dams attributable to their pre-
dams, three hydroelectric energy plants at the dams and the Hilpoltstein lock,
the canal routes to the Altmühlsee and from there to Brombachsee along with
27 other weirs on watercourses, just a few of
which have been expanded to accommodate greater water circulate.
South bank of the Großer Brombachsee, about three kilometers northeast of Langlau and 2.2 kilometers northwest of Ramsberg close to the Weißenberg.
Massive parts of the Kleiner Brombachsee, a receiving water of the Großer Brombachsee, lie throughoutthe
landscape safety area. There are also components and amenities of the primary- Danube Canal that concurrently serve different
purposes: the canal itself between the connection to the Danube and the outlet into the Schwarzach, together with the inlet and outlet structures, as properly because the pumping stations on the south ramp.
Access to the protected area itself is not going to be permitted.
With out the addition, the Regnitz can carry less than 10 m³/s
of water at the Hüttendorf gauge in dry situations. For the explanation that
inflow here might be managed over a large space –
with the exception of low water ranges on the Danube- the
Rothsee is approach smaller in measurement than the Brombachsee.
Excellent article et très informatif! Les services de gestion en ligne offrent une commodité incroyable pour
les entreprises. Merci pour le partage de cet article
et pour les conseils pratiques!
seo продвижение корпоративных сайтов в москве prodvizhenie-sajtov-v-moskve115.ru .
продвижение сайтов гугл цена в москве prodvizhenie-sajtov-v-moskve115.ru .
The One Auto Accident Settlement Mistake Every
Beginning Auto Accident Settlement User Makes auto Accident attorney
generic astelin for sale
продвижение и раскрутка сайтов в москве https://prodvizhenie-sajtov-v-moskve115.ru/ .
Meds information for patients. Drug Class.
can you buy cheap lyrica for sale
All news about medicine. Read now.
It’s going to be end of mine day, except before
end I am reading this great post to increase my experience.
Excellent post. I certainly appreciate this site. Keep writing!
See What Uk Online Shopping Sites For Mobile Tricks The Celebs Are Using uk Online shopping sites for mobile
actos 30 mg price
7 Small Changes That Will Make The Difference With Your Slot Bonuses Bonus slots (offers.sidex.Ru)
where buy generic mestinon price
where buy cheap astelin for sale
You’ll Be Unable To Guess Online Shop Designer Suits’s Benefits Online shop Designer suits
Meds prescribing information. Effects of Drug Abuse.
can i purchase cheap neurontin pills
Best news about medicament. Read information now.
10 Things You Learned In Preschool, That’ll Aid
You In Repairing Upvc Windows 257634
15 Reasons Not To Be Ignoring Free Casino Slots slot tournaments (http://xtgem.com/u/mamri?redir=ahr0chm6ly9qaxn1em0udhyvag9tzs5waha/bw9kpxnwywnljnvpzd0znzazndqx&forum_id=oqp0yi6mk4estv1g3a90e41ut0cm6qo4iwxz1k3)
It’s perfect time to make a few plans for the longer term and it is time to be happy.
I have read this post and if I may just I wish to counsel you some interesting things or tips.
Perhaps you can write next articles relating
to this article. I desire to learn even more things approximately it!
What Is It That Makes Land-Based Slots So Famous? video slots
Hello, after reading this remarkable piece of writing
i am as well glad to share my familiarity here with colleagues.
The Reason Behind Mesothelioma Settlement Is The Most Sought-After
Topic In 2023 Mesothelioma case
Medicament information leaflet. Generic Name.
buying generic cipro pill
Some trends of medicament. Get information here.
You are so awesome! I do not believe I’ve read a single thing like that before.
So great to find someone with a few original thoughts on this
subject matter. Really.. thank you for starting this up.
This site is one thing that’s needed on the web, someone with a bit of originality!
See What Uk Online Shopping Sites For Mobile Tricks The Celebs Are Using
Uk Online Shopping Sites For Mobile
Ten Easy Steps To Launch The Business Of Your Dream Licensed Slots
Business themed slot games
Drugs information sheet. Brand names.
where can i get cialis soft without a prescription
Some about meds. Get information now.