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

London 9 - Lovelace - Shayan Mahnam - JS-Core-1 - Week 3#164

Open
ShayanMahnam wants to merge 4 commits intoCodeYourFuture:mainfrom
ShayanMahnam:main
Open

London 9 - Lovelace - Shayan Mahnam - JS-Core-1 - Week 3#164
ShayanMahnam wants to merge 4 commits intoCodeYourFuture:mainfrom
ShayanMahnam:main

Conversation

@ShayanMahnam
Copy link

No description provided.

Copy link

@jonnywyatt jonnywyatt left a comment

Choose a reason for hiding this comment

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

Brilliant, some advanced techniques here
It's important that code can be easily read by other developers, so don't do too much in a single line, break it into steps. It's better if the code is slightly longer but more readable.
Well done!

*/
function potentialHeadlines(allArticleTitles) {
// TODO
return allArticleTitles.filter(items => items.length < 65);

Choose a reason for hiding this comment

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

The instruction asks for 65 characters or less

Copy link
Author

Choose a reason for hiding this comment

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

fixed 👍

for (let i = 0; i < allArticleTitles.length; i++) {
arr.push(allArticleTitles[i].split(" ").length);
}
return allArticleTitles[arr.indexOf(Math.min(...arr))];

Choose a reason for hiding this comment

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

It can be more readable to break it into more lines. eg

const fewestWords = Math.min(...arr)
const indexOfArticle = arr.indexOf(fewestWords)
const articleTitle = allArticleTitles[indexOfArticle]
return articleTitle

Also, this works when all articles have a different number of words. What if two or more articles have the same number of words? arr.indexOf will find the first match.

Copy link
Author

Choose a reason for hiding this comment

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

looks better now thank you 🥇

function factorial(input) {
// TODO
let sum = 1
for (i = 1; i <= input; i++){

Choose a reason for hiding this comment

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

Don't forget to initialise i with let

Copy link
Author

Choose a reason for hiding this comment

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

Done

@jonnywyatt jonnywyatt added the reviewed A mentor has reviewed this code label Dec 11, 2022
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants