Skip to content

Instantly share code, notes, and snippets.

@isaacssemugenyi
Created June 15, 2021 10:28
Show Gist options
  • Save isaacssemugenyi/5bc863e5275641957e71e97849cae5d7 to your computer and use it in GitHub Desktop.
Save isaacssemugenyi/5bc863e5275641957e71e97849cae5d7 to your computer and use it in GitHub Desktop.
Full code compiled
const users = [
{ name: 'Isaac', age: 29, country_id: 30 },
{ name: 'Jessica', age: 23, country_id: 41 },
{ name: 'Eva', age: 25, country_id: 38 }
]
const countries = [
{ country_name: 'Uganda', country_id: 38 },
{ country_name: 'Kenya', country_id: 41 },
{ country_name: 'Rwanda', country_id: 30 }
]
const JoinedDetails = users.map(user => {
return {
name: user.name,
age: user.age,
country_id: countries.map(country => user.country_id == country.country_id ?
country.country_name : "")
}
})
const finalUserdetails = JoinedDetails.map(result => {
return {
name: result.name,
age: result.age,
country_name: result.country_id.filter(country_name => country_name !== "")[0]
}
})
console.log(finalUserdetails);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment