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
Gambling online has gained a lot of attention in the past decade.
In 1996, there were only fifteen websites. In 1997, there were more than 200.
In 1998 the Frost & Sullivan report stated that online gambling generated $830 million in revenues.
Here is my web blog … blackjack
darknet seiten dark websites
dark web markets tor dark web
%%
Feel free to surf to my homepage – Ck One Perfume
dark internet dark web login
%%
Take a look at my web-site bunk beds triple sleeper
the dark internet dark web access
dark net dark internet
%%
Have a look at my web blog – unisex Perfume
Online gambling has become
extremely popular in the past decade. In 1996, there were only fifteen websites.
By 1997, there were over 200. In 1998 an Frost & Sullivan report stated that
online gambling brought in $830 million in revenue.
The internet betting market offers both bookmakers as well as bettors many benefits.
Online betting sites allow people to bet on their favourite sports, and also earn them money.
These sites offer a variety of ways to deposit money.
my homepage – slots (https://apps.thinkhr.com/api/v1/throne/sso.Json?SSOID=flex&AuthCode=FA93F344FDCB60D46F089F99A5FA3569MTg3NjI0&thrsso=1&redirect=https%3A%2F%2Fbricksofnorthville.com)
how to get on dark web dark web login
free dark web dark web search engines
I loved as much as you’ll receive carried out right here.
The sketch is attractive, your authored material
stylish. nonetheless, you command get got an nervousness over that
you wish be delivering the following. unwell unquestionably come more formerly again as
exactly the same nearly a lot often inside case you shield
this hike.
Poker is legal online. However you must make sure you’re legally able to play.
Most online poker sites require players to be at
least 18 years of age, or at the minimum, the legal
drinking age for your area of residence.
My web-site … live
Online casinos offer many benefits. It isn’t necessary to spend a
lot of money. Many online casinos offer free games and players can test them to determine which games they like best.
My web-site; poker (Marina)
darknet search engine dark web search engines
how to access dark web darknet site
There are many reasons to engage in betting on sports, ranging from the possibility
of making a profit to the fact that it adds excitement and a reason to look forward to the overall viewing
experience.
Also visit my web page :: bets
The popularity of online gambling has increased in the past decade.
In 1996, there were just fifteen websites. In 1997,
there were over 200. In 1998 an Frost & Sullivan report stated that
online gambling brought in $830 million of revenue.
My blog post – blackjack
tor dark web darkwep
Online gambling is governed by various rules and regulations.
In the US for instance it is not possible to establish an online gambling
site in the country where you live however, you are able to base it elsewhere.
Look at my blog post: best
how to get on dark web deep dark web
Hello, its nice paragraph about media print, we all understand media is
a enormous source of data.
There are a myriad of rules and rules that govern online gambling.
For instance in the US it is not possible to have gambling websites
that are located in your home country. However, it could be established elsewhere.
Here is my blog post: gaming
All our deliveries are completely insured and
expertly packed.
Feel free to visit my page – Baccarat Hotel nyc
Online gambling has grown in popularity in the past decade.
In 1996, there were only fifteen websites. By 1997, there
were over 200. According to Frost & Sullivan, online gambling had generated $830
million in revenue in 1998.
Here is my website – blackjack
You can pick the theme you like and play hundreds of online
slots. The payouts can vary but they all adhere to the
same mathematical formula. Look for the “Auto Spin” option to find the most suitable slot game.
%%
my page … Double glazed windows Near Me
%%
Feel free to visit my web-site; triple bunkbed