MANCHESTER CLASS_NW5 - ANVAR AZIZI - MODULE - javaScript-Core-1-Week3 - #125
MANCHESTER CLASS_NW5 - ANVAR AZIZI - MODULE - javaScript-Core-1-Week3#125rebwar1 wants to merge 21 commits into
Conversation
| let arr = [1,2,3]; | ||
| console.log(arr[3]); | ||
| let arr = [1, 2, 3]; | ||
| console.log(arr[3]); // return undefined because the value has not been assigned in index 3 No newline at end of file |
There was a problem hiding this comment.
Good - you have answered all of these correctly.
| let result = []; | ||
| if (n) { | ||
| while (count < n) { | ||
| count === 0 ? result.push(count) : result.push(count * 2); |
There was a problem hiding this comment.
This works well - you don't need to do the check, you can just use result.push(count * 2) as 0x2=0.
|
|
||
| while (count < birthdays.length) { | ||
| if (birthdays[count].split(" ")[0] === "July") { | ||
| july.push(birthdays[count]); |
There was a problem hiding this comment.
Good use of split and index here. You could also use "break" to exit the while loop once you have found the first July date.
| console.log(evenNumbersSum(0)); // should output 0 | ||
| console.log(evenNumbersSum(10)); // should output 90 No newline at end of file | ||
| // console.log(evenNumbersSum()); | ||
| console.log(evenNumbersSum(10)); // should output 90 |
There was a problem hiding this comment.
You need to re-read the question. You need the loop to add up the first n even numbers, starting at 0. So if n=3, you need to add up 0+2+4. If n=10 you need to add up 0+2+4+6+8+10+12+14+16+18.
|
|
||
| for (let i = 0; i < 26; i++) { | ||
| console.log(String.fromCharCode(65 + i), String.fromCharCode(97 + i)); | ||
| } No newline at end of file |
There was a problem hiding this comment.
Good work - adding upper case letters wasn't necessary, but it's good to see that you are interested in how fromCharCode works.
| // TODO - Write for loop code here | ||
| for (let i = 0; i < WRITERS.length; i++) { | ||
| console.log(`${WRITERS[i]} is ${AGES[i]} years old`); | ||
| } |
There was a problem hiding this comment.
Yes, good use of the loop index for both arrays.
| console.log(letter.toUpperCase()); | ||
| } | ||
| console.log("_____________________"); | ||
| console.log(capitalise); No newline at end of file |
There was a problem hiding this comment.
Good you have clearly understood how to use a for loop on an array.
| let city = temperatureService; | ||
| let statementTempCity = cities.map( | ||
| (element) => `The temperature in ${element} is ${city(element)} degrees` | ||
| ); |
| } | ||
|
|
||
| i--; | ||
| } while (i > 50); |
There was a problem hiding this comment.
This will exit after 50 loops, so it might not always find a number over 50. But I also understand why you want it to exit so that you don't end up with an endless loop if your logic is wrong.
| // TODO | ||
| let arrLingth65 = allArticleTitles.filter( | ||
| (item) => item.split("").length <= 65 | ||
| ); |
| let arrLingth65 = allArticleTitles.filter( | ||
| (item) => item.split("").length <= 65 | ||
| ); | ||
| return arrLingth65[arrLingth65.length - 1]; |
There was a problem hiding this comment.
This logic returns the last headline in ARTICLE_TITLES which has 65 characters or less - by co-incidence this is also the headline with the fewest words so your test passes. But if the order of ARTICLE_TITLES is changed, the test will fail. If you have time, try to re-implement this with the correct logic.
| function headlinesWithNumbers(allArticleTitles) { | ||
| // TODO | ||
| let semple = /\d+/; | ||
| let findNum = allArticleTitles.filter((item) => item.match(semple)); |
| function averageNumberOfCharacters(allArticleTitles) { | ||
| // TODO | ||
| // let everage = allArticleTitles.map(el=>el.length) | ||
| let average = allArticleTitles.join("").length / allArticleTitles.length; |
There was a problem hiding this comment.
Good use of join with an empty string.
| // TODO | ||
| let capitalisedSTocks = stocks.map((el) => el.toUpperCase()); | ||
| let highestPrice = closingPricesForAllStocks.map((el) => | ||
| Math.max(...el).toFixed(2) |
There was a problem hiding this comment.
Good use of spread - this is advanced knowledge.
| el.reduce((acc, value, _, { length }) => { | ||
| // console.log(length); | ||
| return acc + value; | ||
| }) / el.length |
There was a problem hiding this comment.
Good use of reduce - this is advanced knowledge. I'm not sure what "_, { length } "does here - the code seems to work without it. You can explain it to me when we meet next week.
| let result = 1; | ||
| for (let i = 1; i <= input; i++) { | ||
| result *= i; | ||
| } |
| let cooking = operation(books, "cooking"); | ||
| const result = [children, non_fiction, cooking]; | ||
| return result; | ||
| } |
There was a problem hiding this comment.
Your functions could have more descriptive names. Also, think about how you might get the list of genres from the array of objects rather than having to hard code it. Don't feel you have to redo this - it's a difficult, stretch exercise and your method is understandable and works well - it's just something to think about.
| } | ||
|
|
||
| return result; | ||
| } |
There was a problem hiding this comment.
Excellent - this is clear concise code and works well.
KarenPudner
left a comment
There was a problem hiding this comment.
Great work! There are a few minor things to look at in my comments, but you have covered a lot of material this week and have clearly understood all the concepts.
while loop once you have found the first July date
No description provided.