First digit in product of an array of numbers | Javascript implementation to find first digit of a single number ; Keep dividing by 10 until it is greater than equal to 10 ; Driver Code
function firstDigit ( x ) { while ( x >= 10 ) x = x / 10 ; return Math . floor ( x ) ; } document . write ( firstDigit ( 12345 ) + " " ) ; document . write ( firstDigit ( 5432 ) ) ;