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

Conversation

@KristinaDudnyk
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: Kristina Dudnyk
  • Your City: London
  • Your Slack Name: KristinaDudnyk

Homework Details

  • Module: Node
  • Week: 1

Notes

  • What did you find easy?

  • What did you find hard?

  • What do you still not understand?

  • Any other notes?

@KristinaDudnyk
Copy link
Author

Front-End of quote-server : https://github.com/KristinaDudnyk/quote-client

//...END OF YOUR CODE
app.get("/quotes/random", (req, res) => {
console.log("/quotes/random");
res.send(loadash.sample(quotes));

Choose a reason for hiding this comment

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

Lodash is one of the option, it is handy but it is also quite old, f/e developer nowadays are tend to not use it in their source code, you can see more here https://thejs.dev/jmitchell/its-time-to-let-go-of-lodash-nqc

I can see you removed the function pickFromArray, actually you can use it to find a random element from your json array.

res.send(pickFromArray(quotes));

console.log("/quotes/search");
let searchValue = req.query.term;
let filteredArr = quotes.filter((element) =>
element.quote.toLowerCase().includes(searchValue)

Choose a reason for hiding this comment

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

Will this work if we give a capital character to term? like quotes/search?term=ABCD

if we want to search in case insensitive, we can consider Regular Expression, here is a example

// Function to search using regular expression
function searchWithRegex(array, term) {
  const regex = new RegExp(term, 'i'); // 'i' for case-insensitive search
  return array.filter(item => regex.test(item));
}

// Perform the search and store the result in a new array
const searchResult = searchWithRegex(arrayToSearch, req.query.term);
res.send(searchResult);

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for your review

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants