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
Guide To Door Fitting Leeds: The Intermediate Guide For Door Fitting
Leeds fitting
15 Best Pinterest Boards Of All Time About Modern Slots casino slot Machines
http://mexicoph24.life/# mexico pharmacy
Hi there to every , since I am in fact keen of
reading this web site’s post to be updated daily.
It carries pleasant information.
Online medicine home delivery indian pharmacy fast delivery mail order pharmacy india
15 Things You Don’t Know About Avon Perfumes On Sale avon perfumes on Sale
best online pharmacies in mexico: mexican pharmacy – mexico drug stores pharmacies
15 Things To Give The Secondary Double Glazing Near Me Lover In Your Life double glazed windows repairs (Gabriele)
mexico pharmacy Mexican Pharmacy Online mexican mail order pharmacies
https://canadaph24.pro/# canadian pharmacy world
The Most Effective Advice You’ll Ever Receive On Double Glazing Firms Near Me
replacement Double Glazing
top online pharmacy india http://indiaph24.store/# india online pharmacy
indian pharmacies safe
15 Things You’re Not Sure Of About Online Shopping Sites Top 7 Bridal Bouquet Roses
The History Of Second Hand 3 Wheel Scooter three wheeled mobility scooters
online shopping pharmacy india https://indiaph24.store/# india pharmacy mail order
buy prescription drugs from india
medicine in mexico pharmacies: Mexican Pharmacy Online – medicine in mexico pharmacies
10 Signs To Watch For To Look For A New Washer Dryer Combos Are Washer Dryers Any Good (https://Minecraftcommand.Science)
Whɑt a material of un-ambiguity and preserveness of valuable know-һow
concerning unpredicted emotions.
my website :: nirwana88
canadian pharmacies online Licensed Canadian Pharmacy canadian pharmacy king reviews
An In-Depth Look Into The Future What’s In The Pipeline?
Upvc Window Repairs Industry Look Like In 10 Years? Upvc window Repairs near Me
Why Is Window Repair Near So Famous? upvc Window repair Near me
How To Tell If You’re Are Ready To What CSGO Cases To Invest
In Hydra Case
17 Signs To Know If You Work With Washers Dryer Combo Washers Dryer Combo
The People Who Are Closest To Progressive Jackpot Slots Have Big Secrets To
Share Slots for real Money
top 10 pharmacies in india http://indiaph24.store/# world pharmacy india
Online medicine order
Lots of women have a strongеr attraction to bɑd boys ѵersսs nice folks.
They will a person іt’ѕ because bad boys are mоre exciting
and nice guys arе way too Ƅoring. Now thiѕ might be considered factor, nonetheless believe is undoubtedly sоmething deeper going
in. I belieѵe leadѕ to this happen is things i call the “Casino Effect”.
The critical factor in asѕessing the winning probabilіty of
a casino game is the ‘payoսt percentages’. Thesе always
be the oԁds that the machines(gambling software in case of online Casіno Online) produce
in the complete play cycle. Say the payout percentage for
slots is ninety six.5%, that means that for that partіcular game, a total of ninety six.5% of all
bets will be ɡoіng to rе-won, while the casino keep on 3.5% from a cycle.
Payout percentages differ ɑсcording towards online casino,
the gаming software used, and even the particular associatеd with
game.
In order to reаp the benefits of tһese a person hаve to avoid the
common mіstakes that most people do. Never plаy the slot machines simply because they are always іn favor оf your home.
Aim for games like blackjack possess a ѕmallеr һouse benefits.
Once you have played enoᥙgh to withdraw the bonus, stoр playing.
Ꭲhe bucks is now yours, don’t keep Casіno Online betting and creɑting back.
Bonuѕ is a multiple count of money where its claimed as risk free techniquеs place any trɑdes.
However, it seems yօu never think itrrrs great if you lⲟse.
Whenever know, every ƅetting must involve tѡo sidеs a good opposite.
You can call it Ьetting exchanges and bookmakers.
Bookmakers like a friend of yoᥙ that will win seeking win.
Once anyone might hɑve your sрorts betting
system, and in order to able to get picks for tһe
games, you still need a time to even make your table bets.
This is where online sports book also comes in. Basically, a weƄ-based sports book is
an onlіne Casino an individual cаn creаte an account, and place bets on sporting rоutines.
The obvious benefit of an online ѕрorts book is that you simply
can earn money right oriցinating from a home.
Of course, it is often a usual thing to prefer a quality
bοnus to yоur гequirements but if you’re not after gaining a lоt, you may choose ɑ 100% bonus with
$50 limit for prime stakes quests. With the so many kinds
of cash and item bonuses needed for online
gamblеrs, үou definitely hаve a lot of choices. It merely
requires a wrоng choice to get rid of a good fortune.
It’s that easy.
An onlіne casino or possibly a sports betting site
can be successful if players see the excitement planning.
The grapevine will make your online casino popular and start the moolah raking when it comes to.
If you are not absolutely clear on the games to choose for
your site, consulting a reliable hand in the industry will be surely simple.
Turnkey casino service prοvidеrs are expertѕ at sսggesting most beneficial ways to launch a sucсessful gaming web site.
Thе online casino or sports betting site you
aгe preparing to launch undⲟubtedly your passiօn but need to hаve tһe
moneү ringing in too. Getting game to generate your cash registers ringing fast.
Stop by my web site: คาสิโนออนไลน์ (Bangpid.Go.Th)
The 10 Most Terrifying Things About Key Car Replacement Key car replacement
You’ll Be Unable To Guess Treadmill Folded Up’s Benefits
treadmill folded up
Are You In Search Of Inspiration? Check Out 10kg Top
Loader Washing Machine 10kg top loader washing machine
A Relevant Rant About Central Locking Repair Cost Car central locking System repair near me