-1

This code is working but if I change N.max to this.max it stops working. I wonder why it doesn't work

const N = {
  min: function(arr) {
    arr.sort((a, b) => a - b);
    return arr.reduce(function(a, b) {
      return a * b / N.max(a, b); // here
    });
  },
  max: (a, b) => (b) ? N.max(b, a % b) : a // and here
}

let arr = [2, 6, 8, 14];

console.log(N.min(arr));
mplungjan
  • 134,906
  • 25
  • 152
  • 209
Shapiro
  • 1
  • 1
  • Does this answer your question? [How does the "this" keyword work?](https://stackoverflow.com/questions/3127429/how-does-the-this-keyword-work) – ASDFGerte Dec 13 '19 at 10:32
  • 1
    specific part of interest: arrow functions. Also, don't break your code by bad comment syntax, it is very hard to read this way. – ASDFGerte Dec 13 '19 at 10:32

1 Answers1

-1

this means 'current object', it is the case that even if you are in N, this is not referring to that const.

If you want to see what actually are referring using this, then as it is javascript, I recommend you to add console.log(this), so you see what this is referring to.

mplungjan
  • 134,906
  • 25
  • 152
  • 209
Iria
  • 319
  • 1
  • 7
  • 18