neveenatik / hyf-javascript1

Homework JavaScript 1
0 stars 1 forks source link

Feedback homework week 3 #2

Open remarcmij opened 6 years ago

remarcmij commented 6 years ago

Hi Neveen, here is my feedback on your homework for week 3.

I think you have done pretty well. I particularly like how you have attempted to make your functions pure and without side effects (but see assignment 7).

Please review on how to use the ternary operator.

1-more.js

2-more.js

3-more.js

Excellent! But I would remove blank lines 4 & 8. And add a blank line before and after a function definition.

4-more.js

Excellent!

5-more.js

6-more.js

Excellent! But be consistent in how you use quotes. Either all single quotes (my preference) or all double quotes.

7-more.js

8-more.js, 9-more.js

10-more.js

11-more.js

12-more.js

Correct!

13-more.js

Correct! But the variable result is unneeded and can be removed.

neveenatik commented 6 years ago

Hi Jim, Thanks for your feedback I wonder why in 7 is it better not to use for loop and better to use only condition. Does it take more time maybe? and for 13 that was included in the assignment I guess it is by mistake because in the original homework there was no result variable. šŸ¤£

  1. What will be the value of result? (And why?) Add your explanation in a JavaScript comment.

const bar = 42; const result = typeof typeof bar;

Thank you very much for all the time you put in giving me your feedback I highly appreciate it <3

remarcmij commented 6 years ago

Hi Neveen,

In 7, the execution time required for the loop is proportional to the number of elements in the array, whereas the execution time when using an index is constant. These two cases are in computer science often denoted using the big O notation: O(N) versus O(1). See this link which I have borrowed from the HYF DataStructures repo: A beginner's guide to Big O notation. For the small array that is used here, it will not make much of a difference, but once your array grow in size this becomes very important.

As for your array comparison function, it is best to make this a pure function again, without side effects. If you follow the principle that two arrays are equal until proven otherwise, you could use a simple function like this.

function compareArrays(array1, array2) {
  if (array1.length !== array2.length) {
    return false;
  }
  for (let i = 0; i < array1.length; i++) {
    if (array1[i] !== array2[i]) {
      return false;
    }
  }
  return true;
}

Good luck!