Ad
  • Custom User Avatar
  • Custom User Avatar

    If the tests don't catch it, don't blame the solution.

  • Custom User Avatar

    Your squeakyClean function should accept an input array of values and return a new array with all empty strings, 0, null and undefined removed.

    It clearly states what to return.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    the function of the example of the instruction is adder, I think it should keep all the return values in that case.
    but it's not a big deal, not the key point of this kata.

  • Custom User Avatar

    It's normal practise use [].someFn .call()/.apply(). If you like save memory, why you chose JS?

  • Custom User Avatar

    Actually the kata description is vague about it.

    .returned(val) — returns true if spy returned val, else returns false

    If I call my spying function and it returned 1, I can say, "Yes, it returned 1". The description does not mention some kind of memory, neither the tests.

  • Custom User Avatar

    You've lost the last word dolor.

  • Custom User Avatar

    In most cases you don't want to do that. If function relay on this in its body (which is equal to window unless function defined in object or "use strict"; is used) you probably will encounter some side effects :) It's safer to pass null and use bind if you need to keep function's current context.

    Perhaps an example will make it clear:

    var obj = {
      val: 0,
      fn: function func() {
        this.val++;
        return this.val;
      }
    }
    window.val = 100;
    obj.fn.val = 1000;
    
    obj.fn(); // 1 -> this === obj
    obj.fn.apply(obj); // 2
    obj.fn.apply(null); // 101
    obj.fn.apply(obj.fn); // 1001
    
    var fn = obj.fn;
    // this now refer to window instance
    fn(); // 102
    fn.apply(null); // 103 -> same as fn()
    fn.apply(fn); // 1002 -> don't expected behaviour
    fn.apply(obj); // 3
    
    var bindedFn = obj.fn.bind(obj);
    // this now is always refer to obj
    bindedFn.apply(obj); // 4
    bindedFn.apply(null); // 5
    bindedFn.apply(obj.fn); // 6