https://www.codewars.com/kata/582746fa14b3892727000c4f
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
You will be given an array of objects (hashes in ruby) representing data about developers who have signed up to attend the coding meetup that you are organising for the first time.
Your task is to return the number of JavaScript developers coming from Europe.
For example, given the following list:
var list1 = [
{ firstName: 'Noah', lastName: 'M.', country: 'Switzerland', continent: 'Europe', age: 19, language: 'JavaScript' },
{ firstName: 'Maia', lastName: 'S.', country: 'Tahiti', continent: 'Oceania', age: 28, language: 'JavaScript' },
{ firstName: 'Shufen', lastName: 'L.', country: 'Taiwan', continent: 'Asia', age: 35, language: 'HTML' },
{ firstName: 'Sumayah', lastName: 'M.', country: 'Tajikistan', continent: 'Asia', age: 30, language: 'CSS' }
];
your function should return number 1.
If, there are no JavaScript developers from Europe then your function should return 0.
Notes:
- The format of the strings will always be Europe and JavaScript.
- All data will always be valid and uniform as in the example above.
This kata is part of the Coding Meetup series which includes a number of short and easy to follow katas which have been designed to allow mastering the use of higher-order functions. In JavaScript this includes methods like: forEach, filter, map, reduce, some, every, find, findIndex. Other approaches to solving the katas are of course possible.
코드
function countDevelopers(list) {
let result = 0;
list.forEach(el => {
if(el.continent === 'Europe' && el.language === 'JavaScript') result++;
});
return result;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Power (8 kyu) / JavaScript (0) | 2023.04.17 |
---|---|
[백준] 8723: Patyki / Node.js (JavaScript) (0) | 2023.04.17 |
[Codewars] Get Planet Name By ID (8 kyu) / JavaScript (0) | 2023.04.16 |
[Codewars] Fix your code before the garden dies! (8 kyu) / JavaScript (0) | 2023.04.16 |
[Codewars] Maximum subarray sum (5 kyu) / JavaScript (0) | 2023.04.14 |
댓글