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
Its like you read my mind! You seem to know a lot about this, like
you wrote the book in it or something. I think that you could do with some pics
to drive the message home a little bit, but other than that, this is
wonderful blog. A great read. I will certainly be back.
http://buyprednisone.store/# prednisone 10mg online
ivermectin 0.5 lotion india ivermectin eye drops ivermectin where to buy for humans
stromectol australia: buy ivermectin uk – ivermectin 50mg/ml
http://stromectol.fun/# stromectol cvs
Hmm it seems like your website ate my first comment (it was extremely long)
so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog.
I as well am an aspiring blog blogger but I’m still new to the whole
thing. Do you have any tips and hints for inexperienced blog writers?
I’d certainly appreciate it.
Таможенное оформление оформления товаров может быть
очень сложным и трудоемким, но при
должной подготовке и знанием всех необходимых требований можно упростить эту процедуру
и избежать возможных проблем, вам поможет таможенный брокер москва во .
В данной статье мы рассмотрим ключевые аспекты таможенного
оформления и дадим полезные советы по каждому
из них.
Первым шагом в таможенном оформлении является изучение всех необходимых нормативных
документов, включая законы, указы, уведомления и другие
документы.
Далее следует сбор всех необходимых документов, таких как таможенная декларация, экспортная и импортная лицензии, сертификат о происхождении товара, транспортные документы
и т.д. Важно убедиться, что все документы в
порядке и соответствуют требованиям
таможенных органов.
That is a really good tip especially to those fresh to the blogosphere.
Simple but very accurate information… Many thanks for sharing this one.
A must read article!
Great article! That is the type of information that should
be shared around the web. Disgrace on Google for not positioning
this publish higher! Come on over and consult with my site .
Thank you =)
amoxicillin online canada buy amoxicillin online uk purchase amoxicillin online without prescription
can you buy amoxicillin over the counter in canada: can you buy amoxicillin over the counter in canada – amoxicillin 500 mg purchase without prescription
lisinopril 40 mg tablet price: rx lisinopril – 30mg lisinopril
Hi, I do think this is an excellent web site. I stumbledupon it 😉
I may come back yet again since i have saved as
a favorite it. Money and freedom is the
best way to change, may you be rich and continue to
help others.
wegovy drug
What’s up mates, its great article about tutoringand
completely explained, keep it up all the time.
stromectol cost: stromectol ebay – ivermectin over the counter
ivermectin coronavirus: ivermectin gel – ivermectin 3mg dosage
Wonderful website. Lots of useful info here.
I am sending it to a few friends ans also sharing in delicious.
And certainly, thank you in your sweat!
The Full Manual to Rain Gutter Setting up, Gutter Guard Installation, and Rain Gutter Cleansing Services
If you are a homeowner, one comprehend the importance of maintaining a functional rain gutter setup. Rain gutters serve a crucial role in shielding your house from rainwater harm by directing water from rainfall away from the roof and base. However, making sure your rain gutters are in top condition demands more than just occasional cleansing. From gutter installation to gutter protector setting up and rain gutter cleaning services, this comprehensive manual covers everything one require to be aware of to keep your gutters in optimal condition.
Gutter Installation
Why Gutters Are Important
Before we dive into gutter installation, let’s comprehend why rain gutters are vital for your home. Rain gutters help prevent rainwater harm by directing water from rainfall away from your home’s foundation, walls, and landscaping. Without proper water drainage, rainwater runoff can cause erosion, basement flooding, mold growth, and constructional harm.
Signs You Need New Rain Gutters
Cracks or Rust: Visible cracks or rust spots indicate that your rain gutters are deteriorating and may require to be replaced.
Sagging or Pulling Away: Rain gutters that sag or pull away from the house are not effectively directing rainwater away and ought to be replaced.
Water Damage: Water stains on the exterior of your home or basement flooding might indicate that your gutters are not functioning properly to do their job.
Frequent Clogs: If your gutters are constantly clogged with debris, it may be time to invest in an updated gutter system that is easier to maintain.
Rain Gutter Materials
When it comes to rain gutter materials, one have various options to choose from:
Aluminum: Lightweight, rust-resistant, and available in a variety of colors.
Vinyl: Affordable, easy to install, and low maintenance.
Steel: Durable and appropriate for regions with harsh weather conditions.
Copper: Elegant, long-lasting, and adds decorative flair to your house.
DIY vs. Professional Installation
While some homeowners may attempt to install rain gutters themselves, it’s often preferable to leave this job to the professionals. Professional gutter installers have the experience, tools, and expertise to ensure that your rain gutters are installed correctly and operate optimally. Plus, hiring a professional can save you time and hassle in the long run.
Gutter Protector Setting up
The Importance of Rain Gutter Guards
Rain Gutter guards are an crucial addition to any gutter system. These protective covers prevent leaves, twigs, and debris from clogging your rain gutters, reducing the requirement for frequent cleaning and reducing the risk of water damage to your house.
Types of Gutter Guards
Mesh Screens: Fine mesh screens permit water to flow through while blocking debris.
Reverse Curve: These rain gutter guards feature a curved surface that directs water into the rain gutter while stopping leaves and debris from entering.
Brush Inserts: Brush-style inserts fit inside the gutter and stop leaves from accumulating while allowing water to flow freely.
Foam Inserts: Foam rain gutter guards block debris while allowing water to filter through.
Professional Installation vs. DIY
While some house owners might try to set up rain gutter guards themselves, professional setting up is often recommended. Professional installers can ensure that rain gutter guards are properly fitted and securely attached, minimizing the risk of debris buildup and water damage.
Gutter Cleaning Services
The Importance of Rain Gutter Cleaning
Regular gutter cleaning is essential for maintaining a functional rain gutter system. Over time, leaves, twigs, and debris can accumulate in your rain gutters, leading to clogs and water overflow. Professional rain gutter cleaning assistance can help avert these issues and extend the life of your rain gutters.
Signs You Need Rain Gutter Cleaning
Visible Debris: If you notice leaves, twigs, or other debris in your rain gutters, it’s time for a cleansing.
Water Overflow: Overflowing gutters during rainstorms indicate that they are clogged and need to be cleaned.
Sagging Gutters: Gutters that sag or pull away from the house may be weighed down by debris and need cleaning.
Gutter installation
Frequency of Gutter Cleaning
The frequency of gutter cleaning depends on several factors, including the surrounding vegetation, climate, and gutter guard installation. In general, it’s recommended to clean your rain gutters at least twice a year, ideally in the spring and fall, to remove seasonal debris buildup.
Conclusion
Maintaining a functional rain gutter system is essential for shielding your home from water damage and preserving its structural integrity. Whether you require rain gutter installation, rain gutter guard installation, or rain gutter cleaning assistance, investing in professional assistance can save you time, money, and hassle in the long run. By prioritizing maintenance, you can ensure that your house remains safe, dry, and secured for years to come.
It’s wonderful that you are getting thoughts from this piece of writing
as well as from our argument made at this time.
%%
Here is my homepage: onlineplayyapokerag.com
whoah this weblog is magnificent i really like reading your posts.
Keep up the great work! You understand, a lot
of people are looking round for this information, you could aid them
greatly.
generic for prinivil: buy lisinopril 20 mg online – lisinopril 30mg coupon
amoxicillin 500 mg for sale: can i buy amoxicillin over the counter – amoxicillin 500 mg
chinaone.net
https://amoxil.cheap/# amoxicillin pills 500 mg
buy prednisone nz: prednisone buy without prescription – 10 mg prednisone
Your means of explaining everything in this paragraph is genuinely pleasant, every one cann
effortlessly understand it, Thanks a lot.
My site; Praca Pomoc Domowa
lasix uses: Over The Counter Lasix – lasix dosage
https://amoxil.cheap/# amoxicillin 500 mg online