Function to convert x into its digit vector and uses count ( ) function to return the required count
function solve ( x ) { var num = [ ] ; while ( x ) { num . push ( x % 10 ) ; x = parseInt ( x / 10 ) ; } num . reverse ( ) ;