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
mexico drug stores pharmacies
https://cmqpharma.com/# mexican online pharmacies prescription drugs
mexican online pharmacies prescription drugs
What Experts Say You Should Know? malpractice lawyers – 1borsa.com –
mexican online pharmacies prescription drugs
https://cmqpharma.com/# mexico drug stores pharmacies
mexican rx online
Rhinitis support
medicine in mexico pharmacies
https://cmqpharma.online/# mexican border pharmacies shipping to usa
п»їbest mexican online pharmacies
Double Glazing Repairs Near Me Tools To Help You Manage Your Everyday Lifethe Only
Double Glazing Repairs Near Me Trick Every Individual Should Be Able To Double glazing repairs near Me
Приветствую. Может кто знает, где найти разные блоги о недвижимости? Пока нашел https://titovloft.ru
Heya i’m for the first time here. I came across this board
and I in finding It really helpful & it helped me out much.
I hope to give one thing back and aid others such as
you helped me.
best online pharmacies in mexico
https://cmqpharma.online/# buying prescription drugs in mexico
mexican pharmaceuticals online
Very shortly this web site will be famous amid all blogging and site-building visitors, due to it’s pleasant posts
Hey there! I understand this is sort of off-topic however I needed to ask.
Does managing a well-established website such as yours take a lot of work?
I am completely new to running a blog but I do write in my journal
daily. I’d like to start a blog so I can share my experience and feelings online.
Please let me know if you have any ideas or tips
for brand new aspiring bloggers. Appreciate it!
I like it whenever people get together and share
opinions. Great blog, keep it up! https://wiki.team-glisto.com/index.php?title=Benutzer:EmmanuelHeighway
Great content on the growth of internet-based gaming.
As an individual who is enthusiastic about this space, I recognize the comprehensive analysis you provided.
If those of you are looking for a new platform to try out, I’ve recently come across an online destination called BetCryptoCasino.net.
It features a diverse selection of casino offerings and sports wagering options, all powered by virtual currencies for smooth and secure payments.
Please investigate it and determine if it aligns with your gaming requirements.
Enjoy!
Stop by my homepage … Decentralized casino
I will right away clutch your rss as I can’t in finding your
email subscription hyperlink or newsletter service. Do you have any?
Please permit me recognise so that I may just subscribe. Thanks.
mexican online pharmacies prescription drugs
https://cmqpharma.com/# mexico drug stores pharmacies
mexico drug stores pharmacies
I think this is one of the most important information for me.
And i am glad reading your article. But wanna
remark on few general things, The web site style is wonderful, the articles is really great :
D. Good job, cheers
Truly no matter if someone doesn’t be aware of then its up to other people
that they will help, so here it occurs.
I am regular visitor, how are you everybody?
This piece of writing posted at this website is actually pleasant.
What Are The Myths And Facts Behind Treatment For Adult
ADHD adhd in adult women treatment (Jeffry)
Very energetic post, I liked that a lot. Will there be a part 2?
I do not know if it’s just me or if perhaps everyone else
experiencing problems with your website. It seems like some of
the text within your posts are running off the screen. Can someone else please
comment and let me know if this is happening to them too?
This might be a issue with my web browser because I’ve had this happen before.
Cheers
where to get generic celexa pills
Yes! Finally something about pvp777.
Nice blog here! Also your site loads up very fast!
What host are you using? Can I get your affiliate link to your
host? I wish my site loaded up as fast as yours lol
medication from mexico pharmacy
https://cmqpharma.com/# mexican mail order pharmacies
pharmacies in mexico that ship to usa
The Reason Behind Wall Mounted Electric Fireplace Is The Most Sought-After Topic In 2023 lynnbolvin.top
buying prescription drugs in mexico
https://cmqpharma.online/# mexican rx online
best online pharmacies in mexico
reputable mexican pharmacies online
https://cmqpharma.online/# medicine in mexico pharmacies
best online pharmacies in mexico
Thanks for sharing your thoughts. I really appreciate your efforts and I will be waiting for your
further write ups thanks once again.
Highly energetic blog, I enjoyed that a lot. Will there be a part 2?
Have a look at my webpage :: asbestos removal in ottawa