Thanks to visit codestin.com
Credit goes to github.com

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

Mohammed Mahdi homework week2 #229

Closed
wants to merge 2 commits into from

Conversation

mohamdmahdi
Copy link

Week 2 homework

@mohamdmahdi
Copy link
Author

Done and changed all the requirements

Copy link
Collaborator

@remarcmij remarcmij left a comment

Choose a reason for hiding this comment

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

Hi @mohamdmahdi, you code contains confusing variable and parameter names. Can you please go through the comments and improve them?

@@ -45,17 +45,33 @@ const tuesday = [
const maartjesTasks = monday.concat(tuesday);
const maartjesHourlyRate = 20;

function computeTasksInHours(maartjesTasksX, celling) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

You probably added an X to this variable name because of an ESLint error about shadowing a variable name. While this solved your problem you have now put the onus on the reader of your code to find out what this X means. A better solution would be to name this parameter simply tasks. It also correctly implies that this function can use to compute the task in hours for *any tasks array, not only the one of Maartje.

The parameter celling is misspelling (ceiling) and also incorrect because it implies a maximum value, whereas here we are concerned with a minimum value. So the name threshold is the accurate name to use.

@@ -45,17 +45,33 @@ const tuesday = [
const maartjesTasks = monday.concat(tuesday);
const maartjesHourlyRate = 20;

function computeTasksInHours(maartjesTasksX, celling) {
const marrtjeTasksInHours = maartjesTasksX
Copy link
Collaborator

Choose a reason for hiding this comment

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

As I indicated in an earlier comment, the name marrtje has a spelling error. Her name is maartje.

function computeTasksInHours(maartjesTasksX, celling) {
const marrtjeTasksInHours = maartjesTasksX
.map(task => task.duration / 60)
.filter(task => task >= celling);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The result of mapping tasks to hours is an array of hours. Therefore you are filtering hours here and a single element of an hours array is an hour:

.filter(hour => hour >= threshold);

function computeEarnings(tasks, hourlyRate) {
// Replace this comment and the next line with your code
console.log(tasks, hourlyRate);
const Taskhours = computeTasksInHours(tasks, 2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Variable, function and parameter names should be in camelCase (start with a lowercase letter). See [Naming conventions)(https://github.com/HackYourFuture/fundamentals/blob/master/fundamentals/naming_conventions.md).

for (const task of Taskhours) {
const Total = task * hourlyRate;
rate += Total;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we're concerned here with practicing array methods, why don't you try a .reduce() (preferred) or .forEach() here?

const Taskhours = computeTasksInHours(tasks, 2);
let rate = 0;
for (const task of Taskhours) {
const Total = task * hourlyRate;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Total -> total

@@ -2,11 +2,12 @@

function doubleOddNumbers(numbers) {
// Replace this comment and the next line with your code
console.log(numbers);
const newNumber = numbers.filter(number => (number % 2 === 1 ? number : false)).map(x => x + x);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The anonymous (arrow) function that you pass as an argument to the filter method should return a boolean (i.e. true or false. In your case you are return false or the number itself. It still works because zero is 'falsy' and non-zero is 'truthy', but that is just sheer luck. Can you fix this by letting the function return a genuine boolean at all times?

Copy link
Collaborator

@remarcmij remarcmij left a comment

Choose a reason for hiding this comment

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

Hi @mohamdmahdi, I still see various comment unaddressed.

@wouterkleijn
Copy link
Contributor

hi @mohamdmahdi can you please address @remarcmij 's comments?

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.

4 participants