Skip to content

Instantly share code, notes, and snippets.

@sandrabosk
Created May 29, 2020 06:23
Show Gist options
  • Save sandrabosk/535c6586303019d96b5796f68f671817 to your computer and use it in GitHub Desktop.
Save sandrabosk/535c6586303019d96b5796f68f671817 to your computer and use it in GitHub Desktop.
// ***********************************************************************************************************************
// https://www.codewars.com/kata/coding-meetup-number-3-higher-order-functions-series-is-ruby-coming
// 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.
// Your task is to return:
// true if at least one Ruby developer has signed up; or
// false if there will be no Ruby developers.
// For example, given the following input array:
// var list1 = [
// { firstName: 'Emma', lastName: 'Z.', country: 'Netherlands', continent: 'Europe', age: 29, language: 'Ruby' },
// { firstName: 'Piotr', lastName: 'B.', country: 'Poland', continent: 'Europe', age: 128, language: 'Javascript' },
// { firstName: 'Jayden', lastName: 'P.', country: 'Jamaica', continent: 'Americas', age: 42, language: 'JavaScript' }
// ];
// your function should return "true".
// ***********************************************************************************************************************
// solution 1:
function isRubyComing(list) {
for (let i = 0; i < list.length; i++) {
if (list[i].language === 'Ruby') return true;
return false;
}
}
// solution 2:
const isRubyComing = list => list.some(({ language }) => language === 'Ruby');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment