Ad
  • Custom User Avatar

    Just checking the available ?? 0 would be enough instead of divsion to NaN. Recipe will always have some vlaue I guess

  • Custom User Avatar

    Hey Les - Wow I really appreciate the detailed response! I love simplicity and intentionality. I love the transition of the loop to the functinal, but especially love the every version. So clean / clear. Alright now I need to go solve 1000x problems so I can start to understand your solutions!

  • Custom User Avatar

    You get better at anything by practicing it. So make a game out of it where you apply it every chance you get. Your approaches in the beginning will look and feel awkward, but you'll get better with practice. Eventually you will arrive at a point where functional makes as much sense as the imperative loop-based implementations -- usually with a lot less code because the loops are hidden behind the higher-ordered functions. Once you are used to functional approaches you are likely to find that bugs are more evident because the loop mechanics aren't in the way (that and you'll learn to avoid side effects, mutability, etc... you'll solve problems with functional composition, keeping your lambda's/arrow-functions short and sweet.)

    At its root, functional list processing is map, filter and reduce. But there are lots of variations of these operations that have names that can make your functional code speak more to its intent than its imperative equivalent. So for example - you could implement a test to see if all of the integers in an array is even like this:

    var all_even = true;
    for(const x of arr)
       all_even &= (x % 2 == 0);
    

    With reduce:

    var all_even = arr.reduce((a,x) => a & (x % 2 == 0), true);
    

    ...but that's less expressive than using the 'every' method on array (not to mention the reduce and the naive loop implementation are less efficient too):

    var all_even = arr.every(x => x % 2 == 0);
    

    Why are they less efficient? Because we could've stopped the moment we hit an odd item because we know that the end result would be false. The every method on Array does this early out without processing the rest of the items only you don't have to think about it.

    The approach I used here could've been much different. See if you can solve and improve upon it, purely functionally.

    Good luck!

  • Custom User Avatar

    I am not an expert in regex, but if I understand

    [^#] means not a #
    ? means match the previous token [^#] zero or one time

    literally match the character

    So altogether, find a character that is NOT # followed by a #. Then if found, the author just replaces that with ''.

  • Custom User Avatar

    wow. this is the coolest recursive I have ever seen

  • Custom User Avatar

    nvm. got it. that's super super smart.

  • Custom User Avatar

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

  • Custom User Avatar

    can you explain the || here?

  • Custom User Avatar

    could you explain the checkUnique function?

  • Custom User Avatar

    this is insane. the way of finding the region is amazing

  • Custom User Avatar

    love how the column was extracted

  • Custom User Avatar

    This is some black magic here. After melting my brain trying to understand this for 10 minutes, it is such a cool solution. I love the functional approach. Any advice on how to get better in functional proramming / to find a functional solution like this?

  • Custom User Avatar

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

  • Custom User Avatar