Ad
  • Custom User Avatar

    You can use foldr instead of foldl, so you don't have to reverse.

  • Custom User Avatar

    This looks nice and short but it iterates through the array twice, which is unnecessary.
    I wouldn't really call this "best practice".

  • Custom User Avatar

    You really shouldn't initialize "smallest" and "largest" like that. What if all the numbers in the array are larger than 999999, but 999999 isn't in the array?
    Then "smallest" would still be 999999. Likewise, largest would be -1 is all numbers are less than that but -1 isn't in the array, so it would return a false
    minimum or maximum. Just set both smallest and largest to "lst[0]" and go from there.

  • Custom User Avatar

    Don't stop haha I like learning stuff. I've been learning Haskell only for a few months now, so I often overlook things like these and/or I just overthink it and it ends up looking way more complicated than it has to be. But I'll remember that one now. Thanks again!

  • Custom User Avatar

    Duh! For some reason it didn't even occur to me that ($) == (\x y -> x y).
    Seems so obvious now haha thanks!