Mohammed Mahdi homework week2#229
Conversation
|
Done and changed all the requirements |
remarcmij
left a comment
There was a problem hiding this comment.
Hi @mohamdmahdi, you code contains confusing variable and parameter names. Can you please go through the comments and improve them?
| const maartjesTasks = monday.concat(tuesday); | ||
| const maartjesHourlyRate = 20; | ||
|
|
||
| function computeTasksInHours(maartjesTasksX, celling) { |
There was a problem hiding this comment.
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.
| const maartjesHourlyRate = 20; | ||
|
|
||
| function computeTasksInHours(maartjesTasksX, celling) { | ||
| const marrtjeTasksInHours = maartjesTasksX |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
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; |
| 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); |
There was a problem hiding this comment.
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?
remarcmij
left a comment
There was a problem hiding this comment.
Hi @mohamdmahdi, I still see various comment unaddressed.
|
hi @mohamdmahdi can you please address @remarcmij 's comments? |
Week 2 homework