Beta

Double Down

Description
Loading description...
Algorithms
Arrays
  • Please sign in or sign up to leave a comment.
  • JohanWiltink Avatar
    mystery.toString = _ => "mystery function";
    pascal.toString = _ => "mystery function";
    nested.toString = _ => "mystery function";
    Object.freeze(mystery); Object.freeze(pascal); Object.freeze(nested);
    

    This doesn't do anything. Those functions are always immediately called in the test suite ( they don't need to be, but they are ), they are never exposed, and the test suite doesn't leak them to the user solution. The source is inaccessible anyway, and if it weren't, Function.prototype.toString.call would still work on them because you didn't disable that.

    That code can be removed without any consequences whatsoever.

  • JohanWiltink Avatar

    The act indirection in the example tests was, to me, quite unreadable. May I suggest

    it( "Example #1: [1, 0, 1, 0, ..]", function() {
      act({ fn: () => mod(2)
          , ns: range(10)
          , expected: [ 1, 3, 1, 5, 1, 3, 1, 7, 1, 3 ]
          });
    });
    
    function act({ fn, ns, expected }) {
      do test
    }
    

    instead of the current situation? I could not make out which arguments went to which function, with function calls nested up to three levels deep.

  • JohanWiltink Avatar
    • yield* [1, 0, 1, 1, 0, 0]; instead of for (let n of [1, 0, 1, 1, 0, 0]) yield n;
    • explicitly specify not only that "there can be duplicate indices", but also they will sometimes not be in order.
    • "Indices are always non-negative integers" is superfluous, given 0 <= element of ns <= 10,000 ( but why is it called "element of ns" instead of "index" !? )

    If indices would be in order ( even if there might be duplicates ), solver would not have to cache results ( which is ugly ) but could generate them on the fly. It's a design decision, but if non-descending indices had been guaranteed, I would have gone for the elegant solution. Just saying.

    • dfhwze Avatar
      • description updated
      • I love the ugly nature of unordered indices in this challenge, let's keep it ;)
      Suggestion marked resolved by dfhwze 4 months ago