Skip to content

Instantly share code, notes, and snippets.

@AndriiBozh
Created February 27, 2019 13:34
Show Gist options
  • Save AndriiBozh/2a4a1607f260ddd21cce66c3987db384 to your computer and use it in GitHub Desktop.
Save AndriiBozh/2a4a1607f260ddd21cce66c3987db384 to your computer and use it in GitHub Desktop.
CodeWars: add a new property
ASSIGNMENT
______________________________
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 an array where each object will have a new property 'greeting' with the following string value:
Hi < firstName here >, what do you like the most about < language here >?
SOLUTION
______________________________
function greetDevelopers(list) {
// thank you for checking out my kata :)
list.map((obj) => obj.greeting = `Hi ${obj.firstName}, what do you like the most about ${obj.language}?`);
return list;
}
greetDevelopers([
{ firstName: 'Sofia', lastName: 'I.', country: 'Argentina', continent: 'Americas', age: 35, language: 'Java' },
{ firstName: 'Lukas', lastName: 'X.', country: 'Croatia', continent: 'Europe', age: 35, language: 'Python' },
{ firstName: 'Madison', lastName: 'U.', country: 'United States', continent: 'Americas', age: 32, language: 'Ruby' }
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment