Convert all substrings of length ' k ' from base ' b ' to decimal | Simple Javascript program to convert all substrings from decimal to given base . ; Saving substring in sub ; Evaluating decimal for current substring and printing it . ; Driver code
function substringConversions ( str , k , b ) { for ( let i = 0 ; i + k <= str . length ; i ++ ) { let sub = str . substring ( i , i + k ) ; let sum = 0 , counter = 0 ; for ( let j = sub . length - 1 ; j >= 0 ; j -- ) { sum = ( sum + ( ( sub [ j ] . charCodeAt ( 0 ) - ' ' . charCodeAt ( 0 ) ) * Math . pow ( b , counter ) ) ) ; counter ++ ; } document . write ( sum + " " ) ; } } let str = " " ; let b = 3 , k = 3 ; substringConversions ( str , b , k ) ;