Ad
  • Custom User Avatar

    Because this is not set at function call (using Function.prototype.call and such) it's null, which becomes the global scope at non-strict mode:

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this#Function_context

    So this is essentially another solution that uses global object.

  • Custom User Avatar

    hope this is sarcasm

  • Custom User Avatar

    I only wrote the original Clojure kata, which is why the description may seem a little vague.

    I don't think the ES6 appraoches are necessary, they are just popular since people have been learning ES6.

    It would have been nice if the author of the JS kata elaborated a little more, but I probably wouldn't do the best job of it, so I'll leave it as is for now.

  • Custom User Avatar

    The kata proposes an algorithm to see if a number is divisible by 13 and that is all; the aim is not to give a mathematical lesson... To have a mathematical proof or informations you can google "rules of divisibility". Maybe you have a good explanation to propose? Anyway thanks for the feedback.

  • Custom User Avatar

    If the actual object field was called name you could use either obj['name'] or obj.name. However, name is a variable that represents some other value in this case.

  • Custom User Avatar

    Operands of logical operators are converted to boolean only to determine which value to return. But the actual return value is obtained from original, non-converted ones.

    function OR(x, y) {
      return x ? x : y;
    }
    

    E.g. in Java you can write the following and nothing is converted.

    int OR (int x, int y) {
      return ((boolean)x) ? x : y;
    }
    

    MDN: Logical Operators

  • Custom User Avatar

    The test cases are always precise because they provide an input and a specific solution that must be returned. It is not the fault of the test case itself but I'm guessing it could be a rounding issue embeded within the code. If both versions pass the tests then essentially they are both correct, even if one method is more precise than the other.

  • Custom User Avatar

    map creates a new array with new items. that is not the goal as I understand it.