Created
May 29, 2020 06:36
-
-
Save sandrabosk/3a047a1ae3bab9d44dd1f915b2425e11 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-6-higher-order-functions-series-can-they-code-in-the-same-language | |
// 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 organising. | |
// Your task is to return either: | |
// true if all developers in the list code in the same language; or | |
// false otherwise. | |
// For example, given the following input array: | |
// var list1 = [ | |
// { firstName: 'Daniel', lastName: 'J.', country: 'Aruba', continent: 'Americas', age: 42, language: 'JavaScript' }, | |
// { firstName: 'Kseniya', lastName: 'T.', country: 'Belarus', continent: 'Europe', age: 22, language: 'JavaScript' }, | |
// { firstName: 'Hanna', lastName: 'L.', country: 'Hungary', continent: 'Europe', age: 65, language: 'JavaScript' }, | |
// ]; | |
// your function should return true. | |
// *********************************************************************************************************************** | |
// solution 1: | |
function isSameLanguage(list) { | |
for (let i = 0; i < list.length; i++) { | |
if (list[0].language !== list[i].language) return false; | |
} | |
return true; | |
} | |
// solution 2: | |
const isSameLanguage = list => list.every(({ language }) => language === list[0].language); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment