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
GEQ Дизайн человека https://humandesignplanet.ru Дизайн человека. 6/2 Дизайн человека.
10 Erroneous Answers To Common Medication For ADHD Questions Do You Know The Correct
Ones? medications used for adhd
Howdy! This is my first visit to your blog! We are a collection of volunteers and starting a
new project in a community in the same niche. Your blog provided us beneficial information to work on. You have done a marvellous job!
cost of viagra in pharmacy: Aebgboype – Malegra FXT
12 Companies Setting The Standard In Assessment For Adhd In Adults adhd assessment For adults cost
acyclovir target pharmacy: best pharmacy store – xlpharmacy viagra
estradiol online pharmacy: american rx pharmacy – pharmacy online australia
Oh my goodness! Amazing article dude! Thanks, However I am experiencing problems with your RSS.
I don’t understand the reason why I cannot join it. Is there anyone else having identical RSS issues?
Anyone who knows the solution will you kindly respond? Thanx!!
bokep anal dengan anjing
Valuable posts Appreciate it!
Feel free to visit my page http://crystal-angel.com.ua/out.php?url=https://directory-fast.com/listings324943/demystifying-casino-sites-an-introductory-guide-to-digital-casinos
I’m really enjoying the design and layout of your blog.
It’s a very easy on the eyes which makes it much more enjoyable
for me to come here and visit more often. Did you hire
out a designer to create your theme? Excellent work!
gen rx pharmacy: online pharmacy viagra australia – med rx pharmacy
Mesothelioma victims are entitled to compensation from several sources, such as liable asbestos law trust funds,
companies and the Department of Veterans Affairs.
снятие ломки на дому снятие ломки на дому .
9 Lessons Your Parents Teach You About Cheap Treadmill Desk cheap Treadmill desk (chessdatabase.science)
I am in fact grateful to the holder of this web site who has shared
this enormous post at here.
Is Car Key Replacement Near Me The Best Thing There Ever Was?
Emergency Car Key Replacement Near Me (79Bo.Cc)
porn cannibalism
watch tour de pharmacy online: misoprostol available in pharmacy – united pharmacy viagra
What’s The Job Market For Car Locks Smith Professionals?
car locks smith (Blake)
15 Gifts For The Emergency Car Key Replacement Lover In Your Life car Key replacement for old cars
What The Heck What Is Integrated Fridge Freezer? fridge
and Freezer [Minecraftcommand.science]
online pharmacy tylenol 3: ohio pharmacy law adipex – complete online pharmacy
scripts rx pharmacy: boots pharmacy mebendazole – buy viagra in pharmacy uk
The Department is not discriminating dependent on race, shade, or countrywide origin in promulgating these ultimate laws, but is demanding thanks procedure protections that will have an effect on learners, staff members, and 3rd get-togethers in an training method or action of recipients that may possibly, for illustration, include things like educational facilities, libraries, museums, and tutorial healthcare centers, among the other sorts of recipients. Most educators say imaginative engage in is considerably much more essential than tutorial finding out for any preschool-age little one. The similar commenter who supported the Department’s proposal for amplified owing procedure security asserted that all pupils, and not just Native American college students, really should obtain the owing system protections essential for Bureau-funded universities and recommended that not supplying much more robust because of procedure protections may possibly violate Title VI. Besides this definite method in which the electoral incapacity injures women farmers, it has a extra or much less specifically injurious influence on all self-dependent girls who maintain themselves and their family members by other than domestic labor. Never overlook who gave you the very best, and be grateful. For illustration, some individuals may perhaps believe that an individual who is transgender is gay. Thus, Executive Order 13132 may well not apply to these final polices. However, these ultimate polices are entirely premised as a condition of receiving Federal resources, and the recipient has the proper to forgo these types of funds if the recipient does not would like to comply with these last regulations.
UCO Дизайн человека https://raschet-karty-dizayn-cheloveka.ru Дизайн человека. 2/5 Дизайн человека.
RAI Дизайн человека https://vkl-design.ru Дизайн человека. 1/3 Дизайн человека.
CDN Дизайн человека https://designmsu.ru Дизайн человека. 5/2 Дизайн человека.
Как не попасть впросак при покупке диплома колледжа или ПТУ в России
pexels.com/@originality-diplomik-1624291569
The Reasons Realsexdolls Is The Main Focus Of Everyone’s Attention In 2023 realsex dolls (http://shop7.kokoo.kr/bbs/board.php?bo_table=inquiry&wr_id=115905)
Prandin: online pharmacy australia paypal – safeway pharmacy store 1818