Last active
May 29, 2020 06:43
-
-
Save sandrabosk/85de6bfdf266b12b1446f8d596e4b494 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// *********************************************************************************************************************** | |
// https://www.codewars.com/kata/coding-meetup-number-12-higher-order-functions-series-find-github-admins | |
// You will be given an array of objects representing data about developers who have signed up to attend the next coding | |
// meetup that you are organizing. | |
// Given the following input array: | |
// var list1 = [ | |
// { firstName: 'Harry', lastName: 'K.', country: 'Brazil', continent: 'Americas', age: 22, language: 'JavaScript', githubAdmin: 'yes' }, | |
// { firstName: 'Kseniya', lastName: 'T.', country: 'Belarus', continent: 'Europe', age: 49, language: 'Ruby', githubAdmin: 'no' }, | |
// { firstName: 'Jing', lastName: 'X.', country: 'China', continent: 'Asia', age: 34, language: 'JavaScript', githubAdmin: 'yes' }, | |
// { firstName: 'Piotr', lastName: 'B.', country: 'Poland', continent: 'Europe', age: 128, language: 'JavaScript', githubAdmin: 'no' } | |
// ]; | |
// write a function that when executed as findAdmin(list1, 'JavaScript') returns only the JavaScript developers who are GitHub admins: | |
// [ | |
// { firstName: 'Harry', lastName: 'K.', country: 'Brazil', continent: 'Americas', age: 22, language: 'JavaScript', githubAdmin: 'yes' }, | |
// { firstName: 'Jing', lastName: 'X.', country: 'China', continent: 'Asia', age: 34, language: 'JavaScript', githubAdmin: 'yes' } | |
// ] | |
// *********************************************************************************************************************** | |
// solution 1: | |
function findAdmin(list, lang) { | |
const admins = []; | |
list.forEach(dev => { | |
if (dev.language === lang && dev.githubAdmin === 'yes') admins.push(dev); | |
}); | |
return admins; | |
} | |
// solution 2: | |
const findAdmin = (list, lang) => | |
list.filter(({ language, githubAdmin }) => language === lang && githubAdmin === 'yes'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment