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
This was beautifully organized. Discover more at بلفاروپلاستی چیست
onlinecanadianpharmacy 24: canadian pharmacy near me – medication canadian pharmacy
canadian drug pharmacy: CanadianMdPharm – canadian drug pharmacy
Best Indian pharmacy: indian pharmacy – Indian Cert Pharm
10 Meetups On Robot Vacuum Deals You Should Attend automated Vacuum
(http://www.metooo.Io)
программа 1с купить с установкой программа 1с купить с установкой .
Good information. Lucky me I ran across your website by accident (stumbleupon).
I’ve bookmarked it for later!
https://indiancertpharm.com/# Indian pharmacy international shipping
canadian pharmacy ltd
I’ve been exploring for a bit for any high quality articles or blog posts on this sort
of house . Exploring in Yahoo I finally stumbled upon this web
site. Reading this information So i am glad to express
that I have a very excellent uncanny feeling I found out just what I
needed. I most indisputably will make certain to
do not overlook this website and provides it a glance regularly.
1с бухгалтерия купить 1с бухгалтерия купить .
An Intermediate Guide To Pragmatic Site 무료슬롯 프라그마틱
вывод из запоя стационар вывод из запоя стационар .
вывод из запоя воронеж вывод из запоя воронеж .
The Top 20ft Shipping Container For Sale UK Experts Are Doing Three Things shipping Containers
вывод из запоя стационар вывод из запоя стационар .
вывод из запоя в стационаре воронежа http://vyvod-iz-zapoya-v-stacionare-voronezh23.ru .
Best Indian pharmacy: Indian pharmacy international shipping – Online pharmacy
программа 1с купить с установкой программа 1с купить с установкой .
check my reference https://my-sollet.com/
Why Karaoke Song Downloads Are Busy 대전유흥 (Shela)
аттестат купить за 11 класс
you can check here https://trusteewallet.org/
Indian Cert Pharm: Indian pharmacy that ships to usa – indian pharmacy online
индивидуалка калуга калуга индивидуалка
The Latest: Phil Mickelson to repay $1 million in SEC case
By ASSOCIATED PRESS
Published: 00:58 GMT, 20 May 2016 | Updated: 00:58 GMT, 20
May 2016
e-mail
NEW YORK (AP) — The Latest on an SEC insider trading case
involving golfer Phil Mickelson (all times local):
7:45 p.m.
A Las Vegas gambler accused of orchestrating an insider
trading scheme involving pro golfer Phil Mickelson posted a $1 million bond
to be freed from federal custody in Nevada ahead of a June 1 court date in U.S.
District Court in New York.
A lawyer for William “Billy” Walters presented a $100,000 check in court to secure the bond, and a U.S.
magistrate judge ordered Walters to surrender his passport and weapons pending trial on 10 conspiracy
and fraud charges.
The 69-year-old Walters could spend the rest of
his life in prison and have to surrender the proceeds of the alleged
scheme. Prosecutors say he passed inside stock information between a director
at a publicly traded food business and Mickelson.
Former Dean Foods Co. board member Thomas Davis pleaded guilty this week in the case and promised to
cooperate in the investigation.
___
12:25 p.m.
Professional golfer Phil Mickelson has agreed to forfeit nearly $1 million dollars that the Securities And Exchange Commission says he
earned in an illegal insider trading scheme.
The SEC says a gambler named William Walters received tips and business information about Dean Foods Co.
from former Dean Foods director Thomas Davis between 2008 and 2012.
Authorities say one of those tips was passed along to Mickelson, who made a big, successful stock trade with the information.
Mickelson’s management group issued a statement Thursday
saying that he had reached an agreement with the SEC to return all of
his profit.
The statement says Mickelson “has no desire to benefit from any transaction that the SEC sees as questionable.”
___
10:51 a.m.
The Securities And Exchange Commission is filing a complaint against professional golfer Phil
Mickelson related to insider trading.
The SEC says a gambler named William Walters received tips and business information about Dean Foods Co.
from former Dean Foods director Thomas Davis between 2008 and 2012.
In 2012, the SEC says Walters called Mickelson, who owed him money,
and urged him to trade Dean Foods stock. The SEC says Mickelson did so the next day and made a profit of $931,000.
Mickelson was not in the field of the Byron Nelson Classic in Irving,
Texas, where play began Thursday morning. Calls to his representatives were not immediately returned.
вывод из запоя в стационаре воронежа https://www.vyvod-iz-zapoya-v-stacionare-voronezh23.ru .
What’s up, after reading this awesome post i am as well
delighted to share my knowledge here with friends.
Mexican Easy Pharm: Mexican Easy Pharm – mexican rx online
Mexican Easy Pharm: Mexican Easy Pharm – Mexican Easy Pharm
I every time used to read paragraph in news papers but now as I am a user of web
so from now I am using net for posts, thanks to web.