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
where to get tizanidine without rx
20 Trailblazers Lead The Way In Birth Injury Lawyer birth injury attorney
In this case, the life insurance firm’s cash.
my web site Bookmarks
Generally I don’t learn post on blogs, but I would like to say that this write-up very pressured me to take a look at and do it!
Your writing taste has been surprised me. Thanks, quite nice article.
10 Birth Defect Lawsuit That Are Unexpected birth defect law Firms
whoah this weblog is great i like studying your posts.
Keep up the great work! You realize, many people are looking round for this information, you could
help them greatly.
The tremendous light stainless steel bottle Urban from 24Bottles
is appropriate for nearly any drink. The drinking bottle is delivered in a cool present packaging, which
makes the 24Bottles the perfect reward. For protected transport
and snug handling, the water bottle is equipped with
a carrying strap and a folding closure. 【360° leak-proof design】: This water bottle is a 360° leak-proof design, when the cap is closed,
the silicone dot pad seals the nozzle and the security lock
prevents the cap from being by chance opened. Learn our article
about stainless steel bottles with engraving or write us an email when you have any questions.
If potential, please ship us your engraving file together with your request if you need branding along with your logo.
No. If the loop bothers you, you will be ready to only lower it off.
These drinking bottles are significantly suitable for fitness, weight
reduction and everyone who pays consideration to their bodily well being.
【Perfect reward for households and friends】 Because the liquid intake boosts our
metabolism, this drinking bottle is a perfect present copy for households and
buddies. For lots of users, high quality seals and results of
the Stiftung Warentest or Öko Check type an orientation foundation if they buy one thing new – also with regard to a brand new drinking bottle.
Comes with a free sponge brush in your convenience.
Thanks to a properly -insulated thermos bottle, this additionally applies to espresso, tea or cool juices, spritzer and co.
porno
Joy Organics organic cbd gummies for diabetes Salve
is also available in two sizes.
I do not know whether it’s just me or if perhaps everyone else experiencing
problems with your site. It appears as though some of the written text on your posts are running
off the screen. Can someone else please comment and let me know if
this is happening to them as well? This might be a problem with my internet browser because I’ve had this happen previously.
Cheers
Useful facts, Kudos.
I would like to thank you for the efforts you have put in writing this site.
I really hope to view the same high-grade content from you in the
future as well. In fact, your creative writing abilities has
inspired me to get my very own blog now 😉
I appreciate, cause I found exactly what I was looking for. You’ve ended my four day long hunt! God Bless you man. Have a nice day. Bye
cleocin gardnerella
Meds information. Cautions.
cheap ipratropium no prescription
Best news about medication. Read information now.
Learning a best language learning apps for kids does not need
to be expensive.
how to get cheap glycomet
Greetings from Idaho! I’m bored to tears at work so I
decided to check out your website on my iphone during lunch
break. I enjoy the knowledge you provide here and can’t wait to take a look when I get home.
I’m amazed at how quick your blog loaded on my cell phone ..
I’m not even using WIFI, just 3G .. Anyhow, fantastic site!
First off I would like to say awesome blog! I had a quick question which I’d like to ask if you do not
mind. I was interested to know how you center yourself and clear your thoughts
prior to writing. I have had difficulty clearing my thoughts in getting my ideas out
there. I truly do take pleasure in writing however it just seems like the first 10
to 15 minutes are usually lost just trying to figure
out how to begin. Any suggestions or hints?
Cheers!
The Best Workers Compensation Case Methods To Rewrite Your Life workers’ Compensation attorney – http://www.maxtremer.com,
We download and play their applications on an Android and iOS device in the workplace to
test them across each user interfaces.
Feel free to visit my web blog; Have a peek here
The 10 Scariest Things About Uk Online Shopping Sites For Electronics
uk online shopping sites for electronics (http://Na.dpsee.Com/member/login.Html?nomemberorder=&returnurl=https://vimeo.com/931865409)
Medicine information for patients. Drug Class.
lisinopril brand name cost
Actual what you want to know about medicines. Read information here.
lisinopril arthritis pain
25 Surprising Facts About Severe Anxiety Disorder Ocd And Anxiety Disorder
Don’t Make This Silly Mistake With Your Fiat 500 Keys lost fiat 500 key
What’s The Current Job Market For Uk Women’s Online Shopping Websites
Professionals? uk women’s online shopping websites
An artificial USP human growth hormone (somatropin).
Here is my web page … Bookmarks
Hello, I enjoy reading all of your article. I wanted to write a little comment to support you.
5 Laws That’ll Help In The Birth Injury Attorney Industry law