Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created May 29, 2020 06:32
Show Gist options
  • Save sandrabosk/4df77ff9e62514ce80ae9fd308d4f95e to your computer and use it in GitHub Desktop.
Save sandrabosk/4df77ff9e62514ce80ae9fd308d4f95e to your computer and use it in GitHub Desktop.
// ***********************************************************************************************************************
// https://www.codewars.com/kata/coding-meetup-number-4-higher-order-functions-series-find-the-first-python-developer
// You will be given an array of objects (associative arrays in PHP) representing data about developers who have
// signed up to attend the next coding meetup that you are organizing. The list is ordered according to who
// signed up first.
// Your task is to return one of the following strings:
// < firstName here >, < country here > of the first Python developer who has signed up; or
// There will be no Python developers if no Python developer has signed up.
// For example, given the following input array:
// var list1 = [
// { firstName: 'Mark', lastName: 'G.', country: 'Scotland', continent: 'Europe', age: 22, language: 'JavaScript' },
// { firstName: 'Victoria', lastName: 'T.', country: 'Puerto Rico', continent: 'Americas', age: 30, language: 'Python' },
// { firstName: 'Emma', lastName: 'B.', country: 'Norway', continent: 'Europe', age: 19, language: 'Clojure' }
// ];
// your function should return Victoria, Puerto Rico.
// ***********************************************************************************************************************
// solution 1:
function getFirstPython(list) {
for (const elem in list) {
if (list[elem].language == 'Python') return `${list[elem].firstName}, ${list[elem].country}`;
}
return 'There will be no Python developers';
}
// solution 2:
const getFirstPython = list => {
const pythonDev = list.find(({ language }) => language === 'Python');
return pythonDev ? `${pythonDev.firstName}, ${pythonDev.country}` : 'There will be no Python developers';
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment