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

MANCHESTER CLASS_NW5 - ANVAR AZIZI - MODULE - javaScript-Core-1-Week3 - #125

Open
rebwar1 wants to merge 21 commits into
CodeYourFuture:mainfrom
CYF-Rebwar:main
Open

MANCHESTER CLASS_NW5 - ANVAR AZIZI - MODULE - javaScript-Core-1-Week3#125
rebwar1 wants to merge 21 commits into
CodeYourFuture:mainfrom
CYF-Rebwar:main

Conversation

@rebwar1

@rebwar1 rebwar1 commented Sep 20, 2022

Copy link
Copy Markdown

No description provided.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good - you have answered all of these correctly.

Comment thread 1-exercises/B-while-loop/exercise.js Outdated
let result = [];
if (n) {
while (count < n) {
count === 0 ? result.push(count) : result.push(count * 2);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread 1-exercises/D-do-while/exercise.js Outdated
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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`);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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`
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes, this is very efficient.

}

i--;
} while (i > 50);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of split.

let arrLingth65 = allArticleTitles.filter(
(item) => item.split("").length <= 65
);
return arrLingth65[arrLingth65.length - 1];

@KarenPudner KarenPudner Sep 21, 2022

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of regex.

function averageNumberOfCharacters(allArticleTitles) {
// TODO
// let everage = allArticleTitles.map(el=>el.length)
let average = allArticleTitles.join("").length / allArticleTitles.length;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of join with an empty string.

Comment thread 2-mandatory/4-stocks.js
// TODO
let capitalisedSTocks = stocks.map((el) => el.toUpperCase());
let highestPrice = closingPricesForAllStocks.map((el) =>
Math.max(...el).toFixed(2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of spread - this is advanced knowledge.

Comment thread 2-mandatory/4-stocks.js
el.reduce((acc, value, _, { length }) => {
// console.log(length);
return acc + value;
}) / el.length

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread 3-extra/1-factorial.js
let result = 1;
for (let i = 1; i <= input; i++) {
result *= i;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good concise code.

let cooking = operation(books, "cooking");
const result = [children, non_fiction, cooking];
return result;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread 3-extra/3-fibonacci.js
}

return result;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Excellent - this is clear concise code and works well.

@KarenPudner KarenPudner left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

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