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
Credit Card Fraud: Easy Methods To Protect Yourself 대출
I blog quite often and I seriously thank you for your information. The article has truly peaked my interest.
I am going to take a note of your site and keep checking for new information about
once a week. I subscribed to your RSS feed too.
Its like you learn my thoughts! You appear to understand a
lot about this, such as you wrote the ebook in it or something.
I think that you could do with a few percent to force the message house a little bit, however instead of that, this is wonderful blog.
A fantastic read. I’ll definitely be back.
Приветствую. Может кто знает, где почитать полезные статьи о недвижимости? Сейчас читаю https://toadmarket.ru
I besides believe hence, perfectly indited post!
Home Loans Bank Or Independent Loan Lender? 대출 금리
Здравствуйте!
Где заказать диплом по необходимой специальности?
Заказать документ о получении высшего образования вы имеете возможность в нашей компании в столице. Мы оказываем услуги по продаже документов об окончании любых университетов РФ. Вы получите необходимый диплом по любым специальностям, включая документы СССР. Даем 100% гарантию, что в случае проверки документов работодателем, никаких подозрений не появится.
http://edmontonoilersclub.com/read-blog/287_where-can-i-buy-a-diploma-or-certificate-at-a-comfortable-price.html?mode=day
Успехов в учебе!
Meds information. Cautions.
can i order generic fluoxetine online
Actual news about drugs. Read information here.
Medicament information sheet. Drug Class.
how to buy cheap elavil without insurance
Best trends of drug. Read here.
I savor, cause I discovered exactly what I
used to be having a look for. You have ended my 4 day long hunt!
God Bless you man. Have a great day. Bye
It’s The Next Big Thing In Medical Malpractice Law legal
Medicament information leaflet. Drug Class.
can you buy cheap fosamax
Best what you want to know about drug. Get information here.
Launching a t-shirt business is often an rewarding
endeavor for individuals wanting to explore the apparel sector.
With an effective plan and dedication, a t-shirt shop can succeed
and become a flourishing business. Here are some essential steps
to consider when launching a t-shirt store.
### Business Plan
Developing a detailed business plan is crucial for the
success and growth of your t-shirt shop. This blueprint must outline your audience, promotional methods,
funding requirements, and business goals. Knowing your audience
can help tailor your t-shirts and advertising to suit their preferences.
### Creating the T-Shirts
Creating the design of your t-shirts is a key element in appealing to customers.
Consider hiring talented graphic designers to develop eye-catching and fashionable designs
that interest your customers. Think about utilizing different printing methods, such as screen printing, digital printing, and heat transfer, based on your budget and the desired
quality of the apparel.
### Choosing Suppliers
Selecting dependable manufacturers for your products is
vital to ensure reliable goods. Identify manufacturers that provide high-quality plain t-shirts
in different colors. Building a strong relationship
with your vendors is important to maintain prompt shipments and affordable prices.
### Setting Up an Online Presence
In today’s digital era, having an digital storefront is important
for connecting with a wider market. Build an attractive and efficient e-commerce site to display
your products. Utilize professional pictures and informative information to
provide buyers a good understanding of what they are buying.
Think about integrating options like trusted payment
options, ratings, and network links to boost visitor experience.
### Marketing and Promotion
Effective promotion is essential to bringing in traffic to your t-shirt shop.
Leverage multiple marketing channels, such as social media, email marketing, influencer marketing, and SEO.
Social media platforms provide you to engage a broad
audience and feature your products.
Sending newsletters can be an effective method to engage with
your audience and notify them about new products, special offers, and upcoming launches.
Collaborating with influencers can additionally assist in accessing targeted customers.
### After-Sales Service
Providing excellent after-sales service is essential for establishing a
faithful audience. Guarantee that your customers have a great shopping experience from
start to finish. Respond to questions and issues promptly and professionally.
Offering easy returns and transparent policies can help building trust with your audience.
### Reviewing Performance
Regularly reviewing your business metrics can help detect aspects
for growth and tweak your {strategies|approaches
11 Ways To Completely Revamp Your Asbestos
Claims Payouts http://www.9363280.xyz
7 Things About Samsung Side By Side Fridge Freezer You’ll Kick Yourself For Not Knowing http://www.36035372.xyz
Приветствую. Может кто знает, где почитать полезные блоги о недвижимости? Сейчас читаю https://toadmarket.ru
gay porn
Medication information for patients. What side effects?
how to get requip without a prescription
Best news about meds. Get information here.
Top Email Icon Packs for Modern Web Design in 2024. Safari Icon: Comprehensive Guide for Designers and Web Developers https://gogeticon.readme.io/reference/top-icon-sets-for-modern-web-design
It’s very effortless to find out any topic on net as compared to textbooks,
as I found this paragraph at this site.
Greetings, fellow enthusiast. I must laud
you on your astute analysis of the subject matter presented in this blog post.
Your discerning observations and verbal commentary have
connected with me, and I discover myself in alignment with the
views you have articulated .
Given your manifest passion in the realm of electronic finance, I would be derelict if I did not provide an call
for you to investigate the exciting world of Crypto Casino.
This innovative platform offers a exceptional and enthralling escapade ,
synthesizing the anticipation of customary casino gaming
with the advanced frameworks of cryptography . I think you would come across
it a most riveting foray. I welcome you to be a part of
us and discover the limitless prospects that are prepared you.
My web-site … online casino customer retention
Приветствую. Может кто знает, где почитать разные блоги о недвижимости? Пока нашел https://toadmarket.ru
An outstanding share! I’ve just forwarded this onto a co-worker who was doing a little research on this.
And he actually bought me breakfast because I stumbled upon it for him…
lol. So let me reword this…. Thank YOU for the meal!!
But yeah, thanx for spending time to discuss this issue here on your website.
Ten Things You Learned In Kindergarden That’ll Help You With Locked Out Of Car
No Spare Key http://www.99811760.xyz
Guide To Back Link Software: The Intermediate
Guide On Back Link Software back link software
The Most Significant Issue With Bunk Beds For
Children And What You Can Do To Fix It Edda Fay
비아그라 한알 가격
비아그라 오리지널 약의 가격
Thanks for the good writeup. It in fact was once a enjoyment account it.
Look complicated to far delivered agreeable from you! However, how can we be in contact?
Medicament information for patients. Cautions.
can you buy warfarin price
All what you want to know about medication. Get now.
Lionel Messi https://inter-miami.lionel-messi-fr.com legendary Argentine footballer, announced his transfer to the American club Inter Miami.