Ad
  • Custom User Avatar

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

  • Custom User Avatar
    • declare your variables
    • do not modify your inputs
    • the IIFE would be better expressed as a recursive function returning a ( the ) result
    • factor out things like sum
    • express your intent more clearly in your code
    • using splice may seem attractive, but it's generally slow; try avoiding it

    It's not as performant as it could be, but it has more or less the right asymptotic performance. It's not as maintainable as it could be ( and this is bigger than you possibly think ), but .. it works.