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
ebzona.icu
We’re a group of volunteers and opening a new scheme in our community.
Your web site offered us with valuable information to work on. You have done
a formidable job and our whole community will be thankful to you.
10 Steps To Begin The Business Of Your Dream Best Medication For Anxiety Disorder Business hyper anxiety Disorder
guvenilir slot siteleri 2024: yeni slot siteleri – slot bahis siteleri
This Is The Good And Bad About Anxiety Disorders Types best medication for social anxiety disorder
15 Lessons Your Boss Would Like You To Know You’d Known About Mesothelioma Claim mesothelioma law firms
The People Who Are Closest To Mesothelioma Lawsuit Uncover
Big Secrets mesothelioma claim
Women are not slaves to their hormones any far more than males are (that, soon after all, would imply that all they do is assume about intercourse). On the HBO collection “Sex in the City,” existence for the 4 feminine people was typically portrayed as a pursuit for a lot more: much more sex, extra shoes, additional cosmos. In 2003, on the other hand, the creator of “Sex and the City,” Candace Bushnell, appeared in a campaign that advocated for significantly less of a little something — menstrual durations. Although any one can establish a intercourse addiction, some are at greater danger than other individuals for developing the situation. There are a variety of danger components that increase an individual’s vulnerability to compulsive sexual behavior this sort of as a genetic predisposition to addiction (which include abnormalities of the brain’s reward circuitry Blum et al., 2012), early trauma and toxic worry (Katehakis, 2009), and early publicity to the supernormal stimulus of pornography (a supernormal stimulus is an artificial exaggeration of a purely natural intuition that can be extra satisfying than the pure stimulus Barrett, 2010 Doidge, 2007 Hilton, 2013). It is crucial to notice that as with all addictive behaviors, individuals with compulsive sexual actions come to be addicted to changing the way they sense. When the war was in excess of, these women were being remaining with actual physical and psychological scars: publish-traumatic worry dysfunction, sexually transmitted ailments and weakened reproductive devices.
ламинированная фанера купить http://www.fanera-kupit11.ru/ .
10 Facts About Mental Health Assessment That Will Instantly Put You In A Positive Mood prom assessment mental Health (https://www.center1339.com/)
ламинированная фанера купить http://www.fanera-kupit11.ru/ .
Hi, i think that i noticed you visited my web site thus i came to return the prefer?.I’m trying to in finding things to enhance my web site!I assume its
ok to make use of some of your ideas!!
Car Key Replacement Ford 101 The Ultimate Guide For Beginners replacement Ford transit key
What’s The Current Job Market For Window Repair Near Me Professionals?
window repair near me
Good-Bye Restaurant Business – Hello Workingfrom Your Home
인천마사지
Way cool! Some extremely valid points! I appreciate you penning this write-up and the rest
of the website is very good.
7 Small Changes That Will Make A Big Difference With Your
Windows Leeds upvc window hinge Repairs Leeds
What Is Depression Treatment Services’ History? History Of Depression Treatment Services What Is Depression Treatment
See What Ford Ka Replacement Key Fob Tricks The Celebs Are Making Use Of Ford Ka Replacement Key Fob
A Step-By’-Step Guide To Picking The Right Audi Car Key Audi Remote key
The No. Question That Everyone In Mesothelioma Law Should Be Able Answer mesothelioma
claim (hi5bisxmsdt1K.com)
Superb, what a website it is! This website provides helpful information to us,
keep it up.
great issues altogether, you simply received a new
reader. What may you recommend in regards to your post that you made some
days in the past? Any certain?
Hello there! Do you know if they make any plugins to assist with Search
Engine Optimization? I’m trying to get my blog to
rank for some targeted keywords but I’m not seeing very good gains.
If you know of any please share. Kudos!
This is very interesting, You are a very skilled blogger.
I have joined your feed and look forward to seeking
more of your fantastic post. Also, I’ve shared your site in my
social networks!
I’ve learn a few excellent stuff here. Certainly price bookmarking for revisiting.
I surprise how much effort you set to make any such excellent informative web site.
What’s The Job Market For Window Doctor Near Me
Professionals? Window doctor near Me
I’ve been exploring for a little bit for any high-quality articles or
blog posts in this kind of space . Exploring in Yahoo I at last stumbled upon this website.
Studying this information So i’m happy to convey that I have an incredibly just right uncanny feeling I came upon just what I needed.
I most surely will make certain to do not fail
to remember this web site and give it a look on a continuing basis.
20 Up-And-Comers To Watch In The Peugeot 308 Key Fob Replacement Industry Peugeot Expert Key fob
https://sweetbonanza.network/# sweet bonanza taktik