-
Notifications
You must be signed in to change notification settings - Fork 0
/
countJsDevs3.js
32 lines (27 loc) · 1.7 KB
/
countJsDevs3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Coding Meetup #1 - Higher Order Functions
// 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.
// The format of the strings will always be Europe and JavaScript.
// All data will always be valid and uniform as in the example above.
// function countDevelopers(list) {
// // loop through the list of objects
// // check for developers from Europe
// // check for javascript developers
// let filteredList = list.filter( dev => dev.language === 'JavaScript').filter( dev => dev.continent === 'Europe');
// // return the count
// return filteredList.length;
// }
const countDevelopers = list => list.filter( dev => dev.language === 'JavaScript').filter( dev => dev.continent === 'Europe').length;
//examples
const 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' }
];
const list2 = [
{ firstName: 'Oliver', lastName: 'Q.', country: 'Australia', continent: 'Oceania', age: 19, language: 'HTML' },
{ firstName: 'Lukas', lastName: 'R.', country: 'Austria', continent: 'Europe', age: 89, language: 'HTML' }
];
console.log(countDevelopers(list1)); // 1
console.log(countDevelopers(list2)); // 0