Ad
  • Custom User Avatar

    This code is so clean it needeth no commentation :)

    Is it?

    • "answer" is not a descriptive variable name. It's not the return value. "sumOfDigits" might be a better name for it.
    • Curly braces are used around the one-line for loop body, but not around the equally one-line if and else bodies. Consistency?
    • Indentation is all over the place (method body is unnecessarily indented and uses 4 spaces instead of 2 as used in the method signature).

    And this is not as much cleanliness as performance: the for loop is always run, but if input length is 1 its result is never used.