Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

London Class 10 - Iryna Lypnyk - Node - Week 1 #319

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

IrynaLypnyk
Copy link

Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in HOW_TO_MARK.md in the root of this repository

Your Details

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

Homework Details

  • Module:
  • Week:

Notes

  • What did you find easy?

  • What did you find hard?

  • What do you still not understand?

  • Any other notes?

Copy link

@ryankav ryankav left a comment

Choose a reason for hiding this comment

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

Think this is really well done! I've added some advanced comments with links to the documentation which you can explore if you want to. As they allow you to write your code in a more concise way but your code is already very readable and easy to understand so well done!

@@ -3,7 +3,10 @@

//load the 'express' module which makes writing webservers easy
const express = require("express");
const lodash = require('lodash');
var cors = require("cors");
Copy link

Choose a reason for hiding this comment

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

Would change this to const. It is best practice to avoid using var, the reason for this is that var has unexpected behaviour when it comes to scoping which can make it hard to reason about your program see the mozilla docs on var for more info.

In this particular case it won't matter but it's definitely better to use either let or const as they respect local (lexical) scoping

Copy link

Choose a reason for hiding this comment

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

I have just seen that this is in the README instructions so I'll raise this with the team as clearly this isn't something you chose, so is unfair to give you feedback on it. I have left the above comment though as it is still worth knowing

if (request.query) {
const term = request.query.term;
if (term) {
const termCaseSencitive = term.toLowerCase();
Copy link

Choose a reason for hiding this comment

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

slight typo on this variable name: termCaseSencitive -> termCaseSensitive

Comment on lines +42 to +48
const quotesWithTerm = quotes.filter((q) => {
const { quote, author } = q;
return (
quote.toLowerCase().includes(termCaseSencitive) ||
author.toLowerCase().includes(termCaseSencitive)
);
});
Copy link

Choose a reason for hiding this comment

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

No need for the q variable as you can destruct this in the function argument.

const quotesWithTerm = quotes.filter(({ quote, author }) => {
  ...
});

Comment on lines +38 to +40
if (request.query) {
const term = request.query.term;
if (term) {
Copy link

@ryankav ryankav Jul 27, 2023

Choose a reason for hiding this comment

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

You can avoid the nested if statements by utilising a guard statement and early returning i.e

if (!request.query?.term) {
  return;
}
// You now know term is defined so can write the rest of the code without an if statement
// and can immediately make the term variable lower case
const term = request.query.term.toLoweCase();
...

The important syntax to note to make this work is the ?. operator which is the optional chaining operator. It allows you to query nested objects as it will return null which evaluates to false if no query was passed in

Comment on lines +55 to +58
if (request.query) {
const word = request.query.word;
response.send(`You said ${word}`);
}
Copy link

Choose a reason for hiding this comment

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

As a stretch could you use the optional chaining operator to make it so that if no word is passed in that you respond with a different message informing the user they didn't say a word

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants