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
http://indiaph24.store/# Online medicine order
My brother recommended I might like this website. He was totally right.
This post truly made my day. You can not imagine simply how much time I had spent for
this info! Thanks!
10 Inspirational Graphics About Erb’s Palsy Legal erb’s palsy law firms
The 10 Most Terrifying Things About Double Glazing Companies Near Me Double glazing companies near me
9 . What Your Parents Taught You About Renault Clio Spare Key renault clio Spare key
reputable indian pharmacies buy medicines from India top 10 online pharmacy in india
zithromax for sale us
15 Gifts For The Avon Rep Login Mk Lover In Your Life avon Rep login Mk
Guide To Replacement Upvc Window Handles: The Intermediate Guide On Replacement Upvc Window Handles replacement upvc window Handles
Why No One Cares About Auto Folding Mobility Scooter Automatic Fold Up Mobility Scooter
What’s The Current Job Market For Erb’s Palsy Attorney Professionals
Like? erb’s
Thаnks for some othesr informative blog. Where elsе could I gett that type of
info written in such an ideal way? I have a challenge that I
am just now worқing on, and I have been on the gⅼancе oᥙt for
such info.
http://canadaph24.pro/# canadian online pharmacy
Why Do So Many People Are Attracted To Double Glazing Repair Leeds?
window repairs leeds (http://www.lzrs1.com/home.php?mod=space&uid=690854)
Situs Alternatif Gotogel Tools To Improve Your Daily Lifethe
One Situs Alternatif Gotogel Trick That Should Be Used By Everyone Know situs alternatif
gotogel, rusla.ru,
12 Facts About Car Key Cutting Manchester To Make You Look Smart
Around The Cooler. Cooler car key cutting manchester – Margart,
Explore the Premier HVAC Repair Service in the Phoenix Area
In the center of Phoenix, where temperatures soar, a dependable
HVAC system isn’t just a luxury—it’s a necessity. That’s why choosing the most reliable HVAC repair service is crucial for ensuring a pleasant and energy-efficient home.
At Best HVAC Repair Phoenix, we excel in delivering excellent solutions
that meet all your cooling and heating needs.
Why Choose Best HVAC Repair Phoenix?
Expertise: Our team is made up of knowledgeable technicians who are adept in the latest HVAC technologies.
They possess the skills to diagnose and fix any issues promptly,
ensuring your system operates smoothly.
Reliability: We understand the urgency of HVAC problems, especially during intense weather.
Our rapid response times and competent repair services mean you won’t be left in discomfort for
long.
Comprehensive Maintenance: Regular maintenance is key to
warding off major breakdowns and lengthening the life of your HVAC
system. We offer thorough maintenance plans to keep your unit in prime condition.
Exceptional Customer Service: At Best HVAC Repair Phoenix, we
prioritize your satisfaction. Our team is committed to providing transparent communication, straightforward pricing, and tailored solutions to meet your specific needs.
Affordability: Quality service shouldn’t be expensive.
We offer affordable pricing and clear quotes, ensuring you get the most value for your money.
Warranty Assurance: We back the quality of our work.
Our services come with warranties, giving you confidence and
certainty in our repairs.
Emergency Services: HVAC emergencies can occur at any time.
That’s why we offer emergency repair services to address your urgent needs swiftly.
Reputation: Our dedication to excellence is manifested in the glowing reviews and recommendations from our happy customers.
Rely on us to deliver dependable and efficient HVAC solutions.
Enjoy the Best in HVAC Repair
Don’t let HVAC issues disrupt your comfort. Opt for Best HVAC
Repair Phoenix for reliable, effective, and economical solutions.
Get in touch with us today to arrange a service or find out more about how we
can improve your home’s heating and cooling systems.
The Motive Behind Pre Owned Mobility Scooters Near Me Is The Most
Sought-After Topic In 2023 Travel Scooters
How Much Do Ford Fiesta Replacement Key Cost Uk Experts Make?
ford fiesta replacement Key Cost
The Most Significant Issue With Double Glazed Window Repair, And How You Can Repair It company
5 Double Glazing Door Repairs Near Me Lessons Learned
From The Professionals Door Double Glazing
10 Quick Tips For Upvc Window Repairs Upvc Window Repairs Near Me (Peatix.Com)
9 Things Your Parents Teach You About Upvc Window Repairs Upvc Window repairs
14 Questions You Shouldn’t Be Uneasy To Ask Windows Replacement misty
20 Fun Details About Replacement Windows Leeds upvc window Hinge Repairs leeds
What’s The Current Job Market For Link Builder Software Professionals?
link Builder software
You’ll Never Guess This Medical Malpractice Lawyers’s Tricks medical Malpractice lawyer
Nine Things That Your Parent Teach You About Double Glazed Window Suppliers Near Me Wood double Glazed Windows
10 Undeniable Reasons People Hate Key Audi audi keyless entry (Muoi)
always i used to read smaller articles which as
well clear their motive, and that is also happening with this paragraph which I
am reading at this time.