Ad
  • Custom User Avatar

    Nice solution! As I was trying to wrap my head around it though, it seems to hit the stack size limit on node 0.12.1 for the last test case, the 5x5 map.

    var map = [[true, true, true, false, true],
        [false, false, true, false, true],
        [true, true, true, true, true],
        [true, false, true, false, false],
        [false, true, true, true, true]];
    
    console.log(solve(map, {x:0,y:0}, {x:4,y:4}));
    

    Output:

    (null):0
    (null)
    
    RangeError: Maximum call stack size exceeded
    
  • Custom User Avatar

    I like that you added the decoded string to the key itself. I kept the decoded string in a separate string so I could access it within the map/forEach. This is a much better approach. Nicely done!

  • Custom User Avatar

    Makes sense. Thanks @surtich!

  • Custom User Avatar

    I don't understand how the pair [3, 7] is earlier in this example:

    sum_pairs([10, 5, 2, 3, 7, 5],         10)
    #              ^-----------^   5 + 5 = 10, indices: 1, 5
    #                    ^--^      3 + 7 = 10, indices: 3, 4 *
    #  * entire pair is earlier, and therefore is the correct answer
    == [3, 7]
    

    If the 5 occurs at index 1, why isn't it "earlier" than the 3 at index 3? Aren't we reading from the left?

  • Custom User Avatar

    The description states that "redo is only possible after an undo". I interpret that to mean that Redo will only work when the immediate last action was an undo. For example, if I do set(), undo(), and then redo(), my last action is a redo(), and so I should not be able to redo(), since my last action is not an undo().

    If that's correct, then why do I see in the provided test cases the following:

      unRe.redo();
      unRe.redo();
      unRe.redo();
      unRe.redo();
    

    Shouldn't this throw an exception?

  • Custom User Avatar

    Yeah, plus creating a copy of the array costs memory and cycles.

  • Custom User Avatar

    TIL you can have multiple declarations separated by comma in a for loop expression (e.g. i++, j--;). Neat!