Hey guys this must be seem repetitive as i already questioned this which is already been answered but this time its a little different.
Previous question: My previous question which is already been answered
So this is my question, i have an array of objects(people) with property called 'name', and 'role'. I have another array which called 'Jobs'. Much better if i use a code sample.
var jobs = ['engineer','scientist','developer'];
var people = [ {name:'John', role:'engineer'},
{name:'Jane', role:'scientist'},
{name:'Jonathan', role:'developer'},
{name:'Jane', role:'engineer'} ];
As you can see object with same property 'name' can be seen but with different role. I want to extract them to a new array using the array of 'jobs' base on their role.
Example output will be:
var peopleWithJobs = [
{name:'John', jobs:['engineer'] }
{name:'Jane', jobs:['scientist', 'engineer'] },
{name:'Jonathan', jobs:['developer'] }
]
if 'name' property value is repeated on the array of 'people' just get the role and push/append to jobs property of the new array 'peopleWithJobs'.
I've been using map and filter higher order functions but im fairly new to javascript and just can't wrap my head around to this logic.