Skip to content
This repository was archived by the owner on Jan 3, 2023. It is now read-only.

London-Class-7 - Omar Sharif - JavaScript - CORE -2 - WEEK - 1 - #47

Closed
omarsharif-gr wants to merge 1 commit into
CodeYourFuture:mainfrom
omarsharif-gr:main
Closed

London-Class-7 - Omar Sharif - JavaScript - CORE -2 - WEEK - 1#47
omarsharif-gr wants to merge 1 commit into
CodeYourFuture:mainfrom
omarsharif-gr:main

Conversation

@omarsharif-gr

Copy link
Copy Markdown

Completed Mandatory exercises

Your Details

  • Your Name:
  • Your City:
  • Your Slack Name:

Homework Details

  • Module:
  • Week:

Completed Mandatory exercises
@omarsharif-gr omarsharif-gr changed the title London_7 - Omar Sharif - JavaScript - CORE -2 - WEEK - 1 London-Class-7 - Omar Sharif - JavaScript - CORE -2 - WEEK - 1 Feb 20, 2021
Comment thread mandatory/1-writers.js
];

function introductorySentence(writer){
return `Hi, my name is ${writer.firstName} ${writer.lastName}. I am ${writer.age} years old, and work as a ${writer.occupation}.`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done for using string interpolation correctly!

Comment thread mandatory/1-writers.js
Comment on lines +65 to +66
const newArray = writers.map(introductorySentence);
console.log(newArray);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, a better method to use would be the forEach method. Similarly to map, it loops through the elements of the array it is acting on and executes the function passed to it as an argument. Differently to map, it doesn't store the return value of the function into an output array (in this case, newArray).

This means that you can use a function that doesn't return a value (also known as a void function in some programming languages) to pass to forEach. Try combining this with rewriting introductorySentence so that it doesn't return a string but rather prints it on the screen.

Comment thread mandatory/1-writers.js
Comment on lines +75 to +79
for (let writersData of writers){
if (writersData.age >= 40 && writersData.age <= 49 && writersData.alive === !true) {
console.log(`Writer ${writersData.firstName} ${writersData.lastName} died at ${writersData.age} years old.`);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of the for ... of statement, and the conditional expression in the if statement.

As an alternative to this approach - do you see how you might be able to rewrite this piece of code using the forEach method?

@Jpsi Jpsi added the reviewed A mentor has reviewed this code label Feb 25, 2021

let thirtyFiveOrOlder = [];
let thirtyFiveOrOlder = [people.filter(value => value.age >= 35)];

@11ma 11ma Apr 12, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all good work Omar, however, i notice with your functions you are surrounding them with extra square brackets. This will return an array within an array, something like this --> [['x', 'y', 'z']], which is not what you're asked for. An additional point will be, although this looks cleaner, please consider readability too.


let powerNetEmails = [];
let powerNetEmails = [people.filter(x.company === 'POWERNET').map(x=>x.email).reverse()];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over here, be careful since you have forgotten to set the x value as an argument in the filter function.


let friendsWithStacie = [];
let friendsWithStacie = [people.filter(x => x.friends.find(x => x.name === 'Stacie Villarreal')).map(x=> `${x.name.first} ${x.name.last}`).reverse];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides the extra square bracket, you are not calling the reverse method on here, which will cause an error.

*/

let friendsWhoCanMultitask = [];
let friendsWhoCanMultitask = [people.filter(x => x.friends.filter(appropriateSkillSet.skills.includes('Multi-tasking'))).flat().map(x=> x.name)];

@11ma 11ma Apr 12, 2021

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, this function does not work, it returns the name of the friends in the list rather than filters the friends who can multitask

@github-actions

Copy link
Copy Markdown

Your coursework submission has been closed because nobody has interacted with it in six weeks. You are welcome to re-open it to get more feedback.

@github-actions github-actions Bot added the Stale label May 25, 2021
@github-actions github-actions Bot closed this May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

reviewed A mentor has reviewed this code Stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants