-
-
Save codebubb/3221d1b878ea6ec0e1b513e21f17ef99 to your computer and use it in GitHub Desktop.
| const users = [ | |
| { id: '88f24bea-3825-4237-a0d1-efb6b92d37a4', firstName: 'Sam', lastName: 'Hughes' }, | |
| { id: '2a35032d-e02b-4508-b3b5-6393aff75a53', firstName: 'Terri', lastName: 'Bishop' }, | |
| { id: '7f053852-7440-4e44-838c-ddac24611050', firstName: 'Jar', lastName: 'Burke' }, | |
| { id: 'd456e3af-596a-4224-b1dc-dd990a34c9cf', firstName: 'Julio', lastName: 'Miller' }, | |
| { id: '58a1e37b-4b15-47c1-b95b-11fe016f7b64', firstName: 'Chester', lastName: 'Flores' }, | |
| { id: 'b4a306cb-8b95-4f85-b9f8-434dbe010985', firstName: 'Madison', lastName: 'Marshall' }, | |
| { id: '6ee904be-e3b0-41c9-b7a2-5a0233c38e4c', firstName: 'Ava', lastName: 'Pena' }, | |
| { id: '7f0ce45a-bdca-4067-968b-d908e79276ce', firstName: 'Gabriella', lastName: 'Steward' }, | |
| { id: '9e525c2d-6fcd-4d88-9ac4-a44eaf3a43e6', firstName: 'Charles', lastName: 'Campbell' }, | |
| { id: 'e789565f-fa5a-4d5e-8f6c-dd126cf995be', firstName: 'Madison', lastName: 'Lambert' }, | |
| ]; | |
| const comments = [ | |
| { userId: '88f24bea-3825-4237-a0d1-efb6b92d37a4', text: 'Great Job!' }, | |
| { userId: '7f053852-7440-4e44-838c-ddac24611050', text: 'Well done, I think I understand now!' }, | |
| { userId: 'e789565f-fa5a-4d5e-8f6c-dd126cf995be', text: 'How do you do that? π²' }, | |
| { userId: '7f053852-7440-4e44-838c-ddac24611050', text: 'OK great thanks' }, | |
| { userId: 'b4a306cb-8b95-4f85-b9f8-434dbe010985', text: 'Cool, thanks!' }, | |
| { userId: '9e525c2d-6fcd-4d88-9ac4-a44eaf3a43e6', text: 'Nice one π' }, | |
| { userId: '6ee904be-e3b0-41c9-b7a2-5a0233c38e4c', text: 'Got it.' }, | |
| { userId: '9e525c2d-6fcd-4d88-9ac4-a44eaf3a43e6', text: 'Thanks!' }, | |
| { userId: '58a1e37b-4b15-47c1-b95b-11fe016f7b64', text: 'Cool π' }, | |
| { userId: '6ee904be-e3b0-41c9-b7a2-5a0233c38e4c', text: 'Great stuff!' }, | |
| ]; | |
| // Exercises | |
| // 1) What is Madison Marshall's user id? | |
| // 2) Who wrote the first comment (assuming the first comment is in position 0 of the comments array) | |
| // 3) Which user commented 'OK great thanks'? | |
| // 4) Add the user's first and last name to each comment in the comments array | |
| // 5) Get a list of the users who haven't commented | |
const users = [
{ id: '88f24bea-3825-4237-a0d1-efb6b92d37a4', firstName: 'Sam', lastName: 'Hughes' },
{ id: '2a35032d-e02b-4508-b3b5-6393aff75a53', firstName: 'Terri', lastName: 'Bishop' },
{ id: '7f053852-7440-4e44-838c-ddac24611050', firstName: 'Jar', lastName: 'Burke' },
{ id: 'd456e3af-596a-4224-b1dc-dd990a34c9cf', firstName: 'Julio', lastName: 'Miller' },
{ id: '58a1e37b-4b15-47c1-b95b-11fe016f7b64', firstName: 'Chester', lastName: 'Flores' },
{ id: 'b4a306cb-8b95-4f85-b9f8-434dbe010985', firstName: 'Madison', lastName: 'Marshall' },
{ id: '6ee904be-e3b0-41c9-b7a2-5a0233c38e4c', firstName: 'Ava', lastName: 'Pena' },
{ id: '7f0ce45a-bdca-4067-968b-d908e79276ce', firstName: 'Gabriella', lastName: 'Steward' },
{ id: '9e525c2d-6fcd-4d88-9ac4-a44eaf3a43e6', firstName: 'Charles', lastName: 'Campbell' },
{ id: 'e789565f-fa5a-4d5e-8f6c-dd126cf995be', firstName: 'Madison', lastName: 'Lambert' },
];
const comments = [
{ userId: '88f24bea-3825-4237-a0d1-efb6b92d37a4', text: 'Great Job!' },
{ userId: '7f053852-7440-4e44-838c-ddac24611050', text: 'Well done, I think I understand now!' },
{ userId: 'e789565f-fa5a-4d5e-8f6c-dd126cf995be', text: 'How do you do that? π²' },
{ userId: '7f053852-7440-4e44-838c-ddac24611050', text: 'OK great thanks' },
{ userId: 'b4a306cb-8b95-4f85-b9f8-434dbe010985', text: 'Cool, thanks!' },
{ userId: '9e525c2d-6fcd-4d88-9ac4-a44eaf3a43e6', text: 'Nice one π' },
{ userId: '6ee904be-e3b0-41c9-b7a2-5a0233c38e4c', text: 'Got it.' },
{ userId: '9e525c2d-6fcd-4d88-9ac4-a44eaf3a43e6', text: 'Thanks!' },
{ userId: '58a1e37b-4b15-47c1-b95b-11fe016f7b64', text: 'Cool π' },
{ userId: '6ee904be-e3b0-41c9-b7a2-5a0233c38e4c', text: 'Great stuff!' },
];
// Q4
comments.forEach((individualComments)=>{
let a = users.filter((individualUsers)=>{return individualUsers.id === individualComments.userId })
individualComments.firstName = (a[0]).firstName
individualComments.lastName = (a[0]).lastName
})
console.log(comments)
// Q5
let b = users.filter((individualUsers)=>{
if (comments.filter((individualComments)=>{return individualUsers.id === individualComments.userId}).length === 0) {
return individualUsers;
}
})
console.log(b);
for the people who want to solve through for loop
***** Exercise 1 *******
for (let i = 0; i<users.length; i++){
if(users[i].firstName === 'Madison' && users[i].lastName === 'Marshall'){
console.log(users[i].id);
}
}
****** Exercise 2 *******
for(let i=0; i<users.length; i++){
if(comments[0].userId === users[i].id){
console.log(users[i]) ;
}
}
***** Exercise 3 ******
let commentId;
for (i = 0; i<users.length; i++){
for(j = 0; j < comments.length; j++){
if(comments[j].text === 'OK great thanks'){
commentId = comments[j].userId
}
} if(commentId === users[i].id){
console.log(users[i])
}
}
**** Exercise 4 ****
If any one know the answer of the last exercise in for loop then kindly post