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
get cheap tetracycline for sale
Has anyone ever faced pushback from friends/family regarding decisions made around relocating even though felt necessary long distance movers new rochelle
Just got settled into my new place thanks to an excellent movers near me service
Предлагаем услуги профессиональных инженеров офицальной мастерской.
Еслли вы искали ремонт телефонов infinix цены, можете посмотреть на сайте: ремонт телефонов infinix в москве
Наши мастера оперативно устранят неисправности вашего устройства в сервисе или с выездом на дом!
Are community events attended early stages settling down beneficial fostering connections among neighbors already residing nearby previously new rochelle long distance moving company
The convenience of hiring local movers in St. Petersburg is unmatched! Discover more tips at local moving st petersburg
Right here is the right web site for anyone who hopes to understand this topic. You know a whole lot its almost tough to argue with you (not that I really will need to…HaHa). You definitely put a brand new spin on a topic which has been written about for many years. Great stuff, just wonderful!
фильмы онлайн бесплатно
clomid buy: clomidonpharm – can you buy clomid
Buzzwords De-Buzzed: 10 Alternative Ways To Say Male Masturbation Sex Toys masturbation toys for men, Dolores,
https://amoxstar.com/# amoxicillin 500 mg tablet
Roulette Betting Guide Davao
If you need tips on how to choose movers moving company
If you’re searching for an exciting and immersive gaming experience, Brawl Pirates
is the perfect choice. This dynamic and engaging
casino game combines thrilling gameplay with the chance to unlock incredible rewards, making it a favorite for players worldwide.
Why Choose Brawl Pirates?
Whether you’re a fan of action-packed slots or just looking for something new, brawl pirates 1win hack
Pirates slot delivers an unforgettable adventure.
The game stands out with its captivating pirate theme, high-quality graphics, and seamless gameplay.
Dive into the world of treasure hunts and pirate battles,
and enjoy the chance to win big while exploring the high seas.
Try Brawl Pirates Casino Demo
For those who are new to the game or want to test their strategies, the Brawl Pirates demo free is an excellent way to explore the mechanics
without any risks. The demo version gives you a hands-on experience
of all the features and bonuses that make the game so popular.
Available on 1win Platform
Fans of the platform will be delighted to find 1win Brawl Pirates.
The game integrates perfectly with the platform, offering smooth functionality and exciting promotions.
Looking for insider tips or strategies? Explore discussions about 1win Brawl
Pirates hack and maximize your experience.
Why You’ll Love This Game
Unique Theme: Immerse yourself in a pirate-themed adventure full of treasures and surprises.
Easy Access: The game is available for free demo play,
so you can try before you commit.
High Rewards: The bonus features and jackpots add to the thrill
of every spin.
Ready to Play?
Brawl Pirates casino game offers something for every player, from casual enthusiasts to serious gamers.
Whether you’re interested in testing the waters with the Brawl Pirates demo or diving straight into the action,
this game promises hours of entertainment.
Set sail today and let Brawl Pirates take you on a thrilling gaming adventure!
Всё, что нужно знать о покупке аттестата о среднем образовании без рисков
Anyone have prior experiences with long-distance movers in Queens? Thinking about going with long distance movers after reading reviews!
Trustworthy movers near me
Looking for affordable local movers in St. Petersburg? I found some deals on st petersburg local moving companies
Tremendous issues here. I am very happy to see your article. Thanks so much and I’m looking ahead to contact you. Will you kindly drop me a e-mail?
zFilm-hd
Получайте кэшбэк до 5% на каждый покупку с картой Сбербанка!
Экономьте на покупках в магазинах, кафе
и онлайн. Простое оформление и удобное
управление через мобильное приложение.
Начните экономить уже сегодня!======>
Все кредитные карты в Бугульме
Купить диплом старого образца, можно ли это сделать по быстрой схеме?
https://amoxstar.com/# amoxicillin 500 mg tablet
What’s The Job Market For Anxiety Psychiatrist Near Me Professionals?
anxiety psychiatrist near Me
Полезная информация как официально купить диплом о высшем образовании
Рекомендую Взломать телефон . Проверенные хакеры, которые предоставляют профессиональные услуги.
An honor witnessing dreams materializing before my eyes thanks largely due partnerships formed among committed individuals striving endlessly towards perfection visible widely amongst target audiences following closely monitored progress viewed online Keechi Creek Builders best home builders in houston
http://amoxstar.com/# amoxicillin 500mg price canada
нужен проект перепланировки квартиры нужен проект перепланировки квартиры .
плотный паралон плотный паралон .
Приобретение диплома ПТУ с сокращенной программой обучения в Москве
where to buy cipro online: ci pharm delivery – buy ciprofloxacin over the counter