Created
February 24, 2022 04:58
-
-
Save natafaye/9a1d67e074a3a318fdec0a8f0739346c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const emailList = [ | |
{ | |
id: 234, | |
author: { | |
firstName: "Natalie", | |
lastName: "Childs" | |
}, | |
to: "Calvin", | |
message: "Heyyyy", | |
read: false, | |
tags: [ | |
"not important", | |
"personal" | |
] | |
}, | |
{ | |
id: 1654, | |
author: { | |
firstName: "Natalie", | |
lastName: "Childs" | |
}, | |
to: "Calvin", | |
message: "What's up?", | |
read: true, | |
tags: [ | |
"work" | |
] | |
}, | |
{ | |
id: 474, | |
author: { | |
firstName: "Dylan", | |
lastName: "Green" | |
}, | |
to: "Calvin", | |
message: "Good day", | |
read: false, | |
tags: [] | |
} | |
] | |
// Map to how we want to display | |
const emailDisplayStrings = emailList.map( email => email.author.firstName + ": " + email.message ); | |
alert(emailDisplayStrings); | |
// Mark all as read | |
// We could do it with a normal for loop | |
// for(let i = 0; i < emailList.length; i) { | |
// emailList[i].read = true; | |
// } | |
// Or with a for of loop | |
// for( const email of emailList ) { | |
// email.read = true; | |
// } | |
// But most experienced developers would do this with .forEach() | |
emailList.forEach( email => email.read = true ); | |
// Filter for all unread | |
const allUnreadEmails = emailList.filter( email => !email.read ) | |
// Find All Emails From One Person | |
const allEmailsFromNatalie = emailList.filter( email => email.author.firstName === "Natalie" ) | |
console.log(emailList); | |
console.log(allEmailsFromNatalie); | |
if(!allEmailsFromNatalie.length) { | |
// only runs if there are no emails from Natalie | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isNotEmpty(paper) { | |
return paper !== ""; | |
} | |
const isNotEmpty = (paper) => { | |
return paper !== ""; | |
} | |
const isNotEmpty = (paper, box) => { | |
console.log(box); | |
return paper !== ""; | |
} | |
isNotEmpty("fdsjkflsd") | |
// get rid of the parenthsis around the parameter (if there's exactly one) | |
const isNotEmpty = paper => { | |
return paper !== ""; | |
} | |
const isNotEmpty = paper => { | |
console.log(paper); | |
return paper !== ""; | |
} | |
// if there's only one line we can get rid of the return | |
// if there's only one line we can get rid of the curly brackets | |
const isNotEmpty = paper => paper !== ""; | |
// Shorten the name of the parameter | |
const isNotEmpty = p => p !== ""; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const emailFromNatalie = { | |
author: "Natalie", | |
message: "Heyyyyy", | |
read: false | |
} | |
alert("Hello " + emailFromNatalie.author) | |
const emailList = [ | |
{ | |
id: 234, | |
author: "Natalie", | |
to: "Calvin", | |
message: "Heyyyy", | |
read: false, | |
}, | |
{ | |
id: 1654, | |
author: "Natalie", | |
to: "Calvin", | |
message: "What's up?", | |
read: true, | |
}, | |
{ | |
id: 474, | |
author: "Dylan", | |
to: "Calvin", | |
message: "Good day", | |
read: false, | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment