-
-
Notifications
You must be signed in to change notification settings - Fork 507
London10_Kristina_Dudnyk_Node_Week1_quote-server #325
base: master
Are you sure you want to change the base?
Conversation
|
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)); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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
Volunteers: Are you marking this coursework? You can find a guide on how to mark this coursework in
HOW_TO_MARK.mdin the root of this repositoryYour Details
Homework Details
Notes
What did you find easy?
What did you find hard?
What do you still not understand?
Any other notes?