DEV Community

Discussion on: Daily Challenge #195 - No Zeroes for Heroes

Collapse
 
aweleczka profile image
Alexander Weleczka

Felt like a bit of recursion is always fun to do.
And I couldn't remember when I used extensions in C# last...

public static int StripTrailingZeros(this int input)
{
    if(input != 0 && input % 10 == 0)
    {
        return (input / 10).StripTrailingZeros();
    }

    return input;
}

Project on GitHub

Collapse
 
aweleczka profile image
Alexander Weleczka
Test Run Successful.
Total tests: 9
     Passed: 9
Total time: 1.6941 Seconds