Skip to content

Instantly share code, notes, and snippets.

@tudorilisoi
Last active August 15, 2019 17:48
Show Gist options
  • Select an option

  • Save tudorilisoi/849433cd6dbbb1859ec74244f1634e9e to your computer and use it in GitHub Desktop.

Select an option

Save tudorilisoi/849433cd6dbbb1859ec74244f1634e9e to your computer and use it in GitHub Desktop.
const persons =[{
id: 'aBcDeFgH',
firstName: 'Juan',
lastName: 'Doe',
age: 32
},
{
id: 'zYxWvUt',
firstName: 'Alex',
lastName: 'Smith',
age: 24
}]
const info = [{
id: 'aBcDeFgH',
occupation: 'architect',
address: {
street: '123 Main St',
city: 'CityTown',
Country: 'USA'
}
},
{
id: 'zYxWvUt',
occupation: 'receptionist',
address: {
street: '555 Ocean Ave',
city: 'Beach City',
Country: 'USA'
}
}]
const mergeDataStreams = ()=>{
let retValue = []
persons.forEach((person)=>{
console.log(`finding info for: ${person.firstName} ${person.lastName}`)
const personInfo = info.find(item=>item.id===person.id)
const mergedInfo = Object.assign({}, person, personInfo)
//const mergedInfo = {...person, ...personInfo}
retValue.push(mergedInfo)
})
return retValue
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment