-
Notifications
You must be signed in to change notification settings - Fork 327
Conversation
yash-kapila
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ihk2018 - I have reviewed your homework and it looks good. However, there is one small missing requirement for one of the questions which needs to be looked into. Could you please have a look? Let me know once that is done and your homework could then be approved? 🙂
| // What to do here? | ||
| // Replace this comment and the next line with your code | ||
| console.log(func); | ||
| return func(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| function createBase(base) { | ||
| // Replace this comment and the next line with your code | ||
| console.log(base); | ||
| return num => base + num; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| function makeUnique(arr) { | ||
| // Replace this comment and the next line with your code | ||
| console.log(arr); | ||
| return [...new Set(arr)]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
| // Changing the argument inside the function does not affect the variable passed from outside the function. | ||
|
|
||
| // Contrary to the first example above; when Javascript deals with objects, it passes by reference/address of the variable. | ||
| // Therefore, changing the argument inside the function affects the variable passed from outside the function. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| if (number % 5 === 0) { | ||
| fiveCallback(number); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple things here:
- You can combine the two loop iterations for creating the numbers array and the
ifconditions. - I think you missed the requirement where you were also supposed to log on console if a number was divisible by both 3 and 5. Hint: a number which is divisible by both 3 and 5 will also be divisible by 15. 🙂
| result += str; | ||
| num--; | ||
| } while (num > 0); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why you added this if check here in the do-while loop and not for or while loop? 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because , for and while loops check the conditions before executing the code. In do - while loop, it executes the condtions atleast once, therefore I wanted to add if condition for preventing do execute the code.
| this.name = 'Lassie'; | ||
| this.color = 'white'; | ||
| this.numLegs = 4; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aahaan. This isn't the best way of creating a constructor function. This is because constructor functions are like a factory which can be used x number of times to create objects(dogs in this case). Thus, if we use the existing constructor function, we would get the same dog everytime while we wanted different ones. A better way to do this would be to use function parameters/arguments.
function Dog(name, color, legs) {
this.name = name;
this.color = color;
this.numLegs = legs;
}
const dog1 = new Dog('Georgie', 'White', 4);
const dog2 = new Dog('Lenny', 'Brown', 4);
// and so on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Yash, i rewrite the code based on your recommodation
|
|
||
| for (let i = 0; i < arr.length; i++) { | ||
| for (let x = 0; x < arr[i].length; x++) { | ||
| product = product * arr[i][x]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
| console.log(arr); | ||
| const newArray = []; | ||
| arr.map(newArr1 => newArr1.map(newArr2 => newArr2.map(newArr3 => newArray.push(newArr3)))); | ||
| return newArray; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logic works fine but imagine if you have to do this for a 4-D or a 5-D array. What happens in that case? Suggestion: try reading about a programming concept called recursion and see if you can apply the same here. 🙂
Also, have a look at Array.prototype.flat method which is newly introduced in MDN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thak you for the advice, i rewite the code
No description provided.