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
Who Is The World’s Top Expert On Adult Adhd Assessment Uk?
Adhd Assessment Near Me
It’s The Complete List Of Gatotkaca Slot Demo Dos And Don’ts akun demo slot gates gatotkaca
How To Outsmart Your Boss On Replacement Lexus Key Lexus car Key copy
Why No One Cares About Motorcycle Accident Compensation Motorcycle Accident Law Firm
How To Determine If You’re Are Ready To Door Repairs
Near Me cheaper
Ten Things You’ve Learned In Kindergarden That’ll Help You With Double Glazing Window Repairs jerealas.top
What Is Bunk Bed Online Store? To Make Use Of It Edda Fay
Привет, друзья!
Где приобрести диплом по нужной специальности?
Заказать документ института можно у нас в столице. Мы оказываем услуги по продаже документов об окончании любых ВУЗов России. Вы получите диплом по любым специальностям, включая документы старого образца. Гарантируем, что при проверке документа работодателем, подозрений не возникнет.
http://www.1-click.pl/excelforum/viewtopic.php?f=3&t=172875&p=173313
Хорошей учебы!
The Most Worst Nightmare Concerning Treadmill Fold Flat Get Real zackfoxworth.top
Medication information for patients. Cautions.
how can i get generic zanaflex without prescription
All about medicine. Get here.
5 Reasons To Be An Online Adult Adhd Assessments And 5 Reasons You Shouldn’t Adhd Assessment Uk Adults
Ten Stereotypes About Malpractice Settlement That Aren’t Always The Truth malpractice lawyers – a.mblg.tv –
Responsible For An Akun Demo Slot Budget? 12 Tips On How To Spend Your Money demo slot princes
(http://www.stes.tyc.edu.tw/xoops/Modules/profile/userinfo.php?uid=1671779)
Medicine information for patients. Drug Class.
get generic levaquin price
Best news about pills. Read here.
You’ll Be Unable To Guess Window Doctor Near Me’s Tricks Window doctor near me
What’s The Job Market For Upvc Repairs Near Me Professionals Like?
Upvc Repairs Near Me
The Most Worst Nightmare About Double Glazing Window Replacement Bring To Life Replacement Window Near Me
Window Glass Repair Near Me Tools To Ease Your Life Everyday http://www.257634.xyz
9 . What Your Parents Taught You About Window Doctor
Near Me window Doctor near Me
Buy Ketozense ACV ACV is a popular weight loss supplement that has been gaining attention for its
use of apple cider vinegar as a key ingredient.
I’m very impressed with this article because it offers a refreshing view on a frequently discussed topic. The author skillfully presents complex ideas in a simple and engaging manner. This article will surely appeal to readers from diverse backgrounds.
Find More Information about the best educational places by Visit Here.
20 Myths About Best Folding Treadmill For Small Space:
Busted zackfoxworth.top
Guide To Upvc Windows Near Me: The Intermediate Guide
On Upvc Windows Near Me upvc Windows near me
https://www.gsfsa.com/user/profile/13006
Do you have anyy video of that? I’d like to find out more
details.
The Most Valuable Advice You Can Receive About Window Glass Replacement Near Me glazier
Search Engine Optimization – Does Anyone Really
Exactly What Works? 백링크 조회
Medication information sheet. Cautions.
buy generic abilify without prescription
Actual news about drug. Get here.
Drug information for patients. What side effects?
mobic price
Some trends of meds. Get now.
Ten Things You Learned About Kindergarden That Will Aid You In Obtaining Window Repair
High Wycombe double glazing companies high wycombe
This Is The History Of Railroad Injuries Lawyer In 10 Milestones Railroad Injuries Lawsuit