Task

Take a   Natural Number   in a given base and return the sum of its digits:

   110         sums to   1
   123410   sums to   10
   fe16       sums to   29
   f0e16     sums to   29


 
function Get-DigitalSum ([string] $number, $base = 10)
{
    if ($number.ToCharArray().Length -le 1) { [Convert]::ToInt32($number, $base) }
    else 
    {
        $result = 0
        foreach ($character in $number.ToCharArray())
        {
            $digit = [Convert]::ToInt32(([string]$character), $base)
            $result += $digit
        }
        return $result
    }
}
 