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
The 10 Most Terrifying Things About White Window Handles white window handles
The Daftar Akun Togel Resmi Case Study You’ll Never Forget Toto Macau
Very rapidly this site will be famous amid all blogging and site-building viewers, due to it’s fastidious articles
or reviews
Here is my blog post – phenq pm results
Yоu саn bеt оn а ѕіnglе numbеr оr dіffеrеnt grоuрѕ оf numbеrѕ іn rоulеttе.
The Most Effective Double Glazed Window Handle Tricks For Changing Your Life Window Handle Replacement Cost
I’m not that much of a internet reader to be honest but your blogs really nice, keep
it up! I’ll go ahead and bookmark your website to come back later on. Cheers
Hello there! Do you use Twitter? I’d like to follow you if that would be okay.
I’m definitely enjoying your blog and look forward to new updates.
My family all the time say that I am killing my time here at web, except I
know I am getting experience daily by reading such pleasant
posts.
A Look Into The Future: What Will The Arabica Beans Industry Look Like In 10 Years?arabica coffee Beans
A Rewind What People Said About Locksmith Near Me Auto 20 Years
Ago auto locksmith service (https://directorylandia.com/listings258071/20-best-tweets-of-All-time-about-car-key-locksmith-Near-me)
cheapest rybelsus pills: rybelsus pill – semaglutide cost
ozempic coupon: ozempic generic – ozempic
ozempic: Ozempic without insurance – ozempic coupon
I am truly delighted to read this website posts which consists of lots of helpful data, thanks for providing such data.
The ketogenic diet has gained immense popularity over the past few years, with a massive following due to its promise of weight loss and improved health markers.
Here is my web site: https://wiki.flashcorponline.com/index.php/Liberty_Bites_Keto:_Why_Electrolytes_Matter_In_Your_Keto_Snack_Choices
Discovered an article that will definitely interest you – don’t miss the chance to familiarize yourself https://www.empowher.com/user/4367496
Why Do So Many People Want To Know About Adult Female Adhd Symptoms? hyperactive adhd symptoms (Remona)
В магазине сейфов предлагают купить сейф интернете купить сейф москва
14 Smart Ways To Spend Your Extra Portable Ramp Wheelchair Budget Permanent Wheelchair Ramps, Imoodle.Win,
Hmm it looks like your website ate my first comment (it was super long) so I guess I’ll just sum it up what I wrote
and say, I’m thoroughly enjoying your blog.
I too am an aspiring blog writer but I’m still new to everything.
Do you have any recommendations for beginner blog writers?
I’d genuinely appreciate it.
Přijetí hypoteční platby může být obtížné pokud
nemáte rádi čekání v dlouhých řadách , vyplnění
závažné formuláře , a odmítnutí úvěru na základě vašeho úvěrového
skóre . Přijímání hypoteční platby může být
problematické, pokud nemáte rádi čekání v dlouhých řadách ,
podávání extrémních formulářů , a odmítnutí úvěru na základě vašeho
úvěrového skóre . Přijímání hypoteční platby může být problematické , pokud
nemáte rádi čekání v dlouhých řadách , vyplnění extrémních formulářů a odmítnutí
úvěrových rozhodnutí založených na úvěrových skóre .
Nyní můžete svou hypotéku zaplatit rychle a efektivně v České republice. https://groups.google.com/g/sheasjkdcdjksaksda/c/CadHA4mlHE8
http://rybelsus.shop/# cheapest rybelsus pills
종로호빠 처음이라 서툰 분들은 오래된 영업진들이 잘 코칭 해드리겠습니다.
10 Things We All Love About Audi Spare Key audi Tt key fob
Why You Must Experience Bunk Beds For Kids At The Very Least Once In Your Lifetime bunk Bed for Kids
semaglutide tablets rybelsus pill rybelsus cost
An Best Portable Mobility Scooter Uk Success Story You’ll Never Believe best lightweight Portable mobility Scooter
https://rybelsus.shop/# semaglutide tablets
Профессиональный сервисный центр по ремонту электросамокатов в Москве.
Мы предлагаем: ремонт колеса электросамоката
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
How Bunk Bed Kids Was The Most Talked About Trend Of 2023 Kids Bunk Bed With Storage