Condition to check if the number is convertible to another base
if ( val ( str . charAt ( i ) ) >= base ) { return - 1 ; } num += val ( str . charAt ( i ) ) * power ; power = power * base ; } return num ; }