Count digits present in each element of a given Matrix | JavaScript program to implement the above approach ; Function to count the number of digits in each element of the given matrix ; Traverse each row of arr [ ] [ ] ; Traverse each column of arr [ ] [ ] ; Store the current matrix element ; Count the number of digits ; Prlet the result ; Given matrix
let M = 3 ; let N = 3 ; function countDigit ( arr ) { for ( let i = 0 ; i < M ; i ++ ) { for ( let j = 0 ; j < N ; j ++ ) { let X = arr [ i ] [ j ] ; let d = ( Math . floor ( Math . log10 ( X ) * 1.0 ) + 1 ) ; document . write ( d + " " ) ; } document . write ( " " ) ; } } let arr = [ [ 27 , 173 , 5 ] , [ 21 , 6 , 624 ] , [ 5 , 321 , 49 ] ] ; countDigit ( arr ) ;