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
Very nice post. I just stumbled upon your weblog and
wanted to say that I’ve truly enjoyed browsing your
blog posts. In any case I will be subscribing to your feed and I
hope you write again very soon!
Medicament information sheet. Drug Class.
can i get generic dilantin without a prescription
Best news about medicines. Get information here.
About The Chex System – Opening A New Bank Account With Bad
Credit 사업자 대출
You actually revealed this terrifically!
Here is my web page :: https://www.ebay.com/str/kapowukstore/T-SHIRTS/_i.html?store_cat=46122063012
Приветствую. Может кто знает, где найти разные статьи о недвижимости? Пока нашел https://toadmarket.ru
Why You Should Concentrate On Improving Coffee Machine Tassimo
4182051
A Comprehensive Guide To Boot Scooters. Ultimate Guide To Boot
Scooters http://www.arlennizo.top
See What Double Glazing Units Near Me Tricks The Celebs Are Using double glazing units near me
Essential Trageted Traffic Tips 검색엔진최적화; organicsalonaspen.com,
https://www.slotpg168.bet/ SLOTPG168
Why It’s Okay To Hire A Mortgage Loan 저신용자 대출
Приветствую. Может кто знает, где найти полезные статьи о недвижимости? Сейчас читаю https://toadmarket.ru
Приветствую. Подскажите, где найти полезные статьи о недвижимости? Пока нашел https://toadmarket.ru
WoW PvE Raid Carry – guide for efficient
14 Smart Strategies To Spend Left-Over Treatment
For ADHD In Adults Budget Treatment For Inattentive Adhd In Adults
Hello, its good post regarding media print, we all be familiar with media is a wonderful source of data.
Aw, this was a very good post. Finding the time and actual effort to create
a really good article… but what can I say… I put things off a lot and never manage to get
anything done.
Starting a t-shirt business is an thrilling venture for
business owners looking to enter the clothing market. With a solid plan and commitment, a t-shirt shop may
succeed and grow into a flourishing venture. Here are some essential steps to think about
when launching a t-shirt shop.
### Business Plan
Developing a detailed strategy is crucial for the success and growth of your t-shirt shop.
This strategy should outline the customer base, advertising plans, funding requirements, and business goals.
Knowing your customer base can help customize your t-shirts and promotional activities to cater to their
interests.
### Creating the T-Shirts
The design of your t-shirts is a important aspect in drawing buyers.
Consider hiring talented designers to create attractive and stylish graphics that interest your target market.
Consider employing different printing methods,
such as screen printing, direct-to-garment printing, and sublimation, according to your preferences and the quality level of the
t-shirts.
### Choosing Suppliers
Finding dependable manufacturers for your products is vital to guarantee reliable
quality. Identify manufacturers that supply high-quality plain t-shirts in various
sizes. Creating a strong partnership with your vendors will help ensure
prompt delivery and competitive prices.
### Building an Online Shop
In today’s digital world, having an digital storefront is crucial for connecting with a more
extensive market. Create an appealing and functional website
to display your apparel. Utilize high-quality images and detailed information to offer visitors a good understanding of what they are purchasing.
Look into adding features like safe transactions options, feedback, and social media integration to boost visitor experience.
### Marketing and Promotion
Targeted promotion is key to bringing in traffic to
your t-shirt shop. Leverage various marketing channels, like social media,
email campaigns, partnering with influencers, and search
engine optimization. Platforms like Instagram, Facebook, and TikTok
enable you to reach a vast customer base and showcase your products.
Email marketing is another method to stay in touch with your customers and update them about new products, special offers, and forthcoming launches.
Partnering with influencers can also boost in accessing potential
buyers.
### Customer Service
Providing outstanding after-sales service is vital for
creating a loyal clientele. Guarantee that your buyers have a great experience from start
to finish. Handle concerns and issues efficiently
and courteously. Offering convenient refunds and transparent terms can assist establishing reliability with your clients.
### Reviewing Performance
Consistently reviewing your business metrics can help identify areas for improvement and adjust your {strategies|approaches
You’ll Never Guess This Upvc Door Repairs Near
Me’s Secrets upvc door repairs near me; Comunidadeqm.Marcelodoi.com.br,
Meds information leaflet. Short-Term Effects.
how to buy dramamine without a prescription
Everything information about medication. Get information here.
Lorem Ipsum has been the industry’s standard dummy text https://marielabertuggia.es/lxxnkhn of type and scrambled it to make a type specimen book.
The No. One Question That Everyone Working In Veterans Disability
Attorney Should Be Able To Answer veterans disability Lawsuits
Hello, I read your blog daily. Your humoristic style
is witty, keep doing what you’re doing!
Feel free to visit my web page – http://superpremium2.premium4best.eu/
Wall Mount Electric Fireplace Tips From The Top In The Business http://www.lynnbolvin.top
Действительно это удобный онлайн сайт. Посетите также мою страничку https://karmadishoom.com/%d1%83%d1%81%d0%ba%d0%be%d1%80%d0%b5%d0%bd%d0%b8%d0%b5-%d0%b8%d0%bd%d0%b4%d0%b5%d0%ba%d1%81%d0%b0%d1%86%d0%b8%d0%b8-3/
5 Killer Quora Answers On Window Doctor Near Me window doctor near me
Всем привет! Подскажите, где почитать разные статьи о недвижимости? Пока нашел https://toadmarket.ru
Medicament information. What side effects can this medication cause?
can you buy cheap ceftin price
Everything trends of drug. Read information now.
Are The Advances In Technology Making Car Boot Scooters Better Or Worse?
Seth
Guide To Medical Malpractice Compensation: The Intermediate
Guide To Medical Malpractice Compensation medical malpractice