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
If you are looking to buy a verified Cash App account, it’s important to consider the benefits.
Verified accounts offer increased security, higher transaction limits, and
access to additional features. However, it’s crucial to find reliable sellers to avoid
scams or fraudulent accounts. Take the time to research and verify the legitimacy
of the seller before making any purchase. Remember,
a verified Cash App account can provide a seamless and secure payment experience.
famous handbag designers (Chas)
%%
My web site: delta-8 thc gummies for Sale (https://pediascape.science/wiki/This_Is_The_Ugly_Facts_About_Delta8_THC_Gummies)
%%
Visit my web blog Mesothelioma Firms
https://kamagra.team/# Kamagra tablets
asbestos mesothelioma attorneys (Denice)
%%
my web site; Part Time Work From Home Jobs (http://Sj.Fineweb.Co.Kr/)
meso attorney
railway cancer concession form [motogpdb.Racing]
asbestos lawsuit after death
%%
My homepage – attorney
Window Repairs Walthamstow
%%
Stop by my blog post mobility scooters green Power
%%
Also visit my web-site; Bmw Key (https://Click4R.Com)
mesothelioma lawsuit kentucky; Sherrie,
I think that everything composed was actually very logical.
However, consider this, what if you added a little information? I
am not saying your information isn’t good., however what if you added something that makes people want more?
I mean JS 依照元素出現數量排序 –
馬老師 雲端研究室 is a little plain. You might look at Yahoo’s
home page and see how they create news headlines
to get people to open the links. You might add a related video or a related picture or two
to get people interested about everything’ve written. Just my opinion, it might bring your blog a little livelier.
%%
Also visit my web-site :: broad-spectrum cbd products;
best-broad-spectrum-cbd-o93827.bluxeblog.com,
%%
Check out my homepage – Keto Max Pro
%%
My blog post; double glazing in hemel hempstead – https://cookeji.com/home.php?mod=space&uid=208540,
%%
Look at my web blog: ghost immobiliser fitting
%%
Feel free to visit my homepage – toyota Replacement
key fob (P3terx.com)
asbestosis asbestos mesothelioma Attorney
I enjoy what you guys tend to be up too. This kind of clever work and exposure!
Keep up the wonderful works guys I’ve included you guys to our blogroll.
%%
Feel free to surf to my site … mercedes Replacement Key
I have read so many content about the blogger lovers
but this article is actually a fastidious piece of writing, keep
it up.
%%
Stop by my webpage: electricians In Hertfordshire
asbestos mesothelioma lawsuit (asbestoslawsuitsettlement66155.full-design.com)
asbestos Claim payouts (https://kikipedia.win)
designer handbags in sale (designerhandbagsred70485.Wssblogs.Com)
Buying a verified Cash App account comes with many benefits.
With a verified account, you can enjoy a higher transaction limit,
enhanced security features, and access to exclusive Cash
App features. Don’t miss out on the advantages – get a verified Cash App account today!