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

Conversation

@ihk2018
Copy link

@ihk2018 ihk2018 commented Sep 11, 2019

No description provided.

Copy link

@yash-kapila yash-kapila left a 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();

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;

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

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.

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

Choose a reason for hiding this comment

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

Couple things here:

  1. You can combine the two loop iterations for creating the numbers array and the if conditions.
  2. 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);
}

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? 🙂

Copy link
Author

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

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

Copy link
Author

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

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;

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.

Copy link
Author

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

@yash-kapila yash-kapila self-assigned this Sep 19, 2019
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.

3 participants