Move all digits to the beginning of a given string | Function to move all the digit to the beginning of the string ; Calculate the string length ; Stores the digits ; Stores the non - numeric character ; Traverse the string and check if there is a digit ; If character is a digit , add it to the string digits ; Otherwise , add it to the string nonNumericCharacter ; Append both the strings ; Print the string ; Given String str
function moveAllDigitAtBeginning ( str ) { var len = str . length ; var digits = [ ] ; var nonNumericCharacter = [ ] ; var temp = str . split ( " " ) ; for ( const c of temp ) { if ( c . charCodeAt ( 0 ) >= 48 && c . charCodeAt ( 0 ) <= 57 ) { digits . push ( c ) ; } else { nonNumericCharacter . push ( c ) ; } } digits . push ( nonNumericCharacter . join ( " " ) ) ; document . write ( digits . join ( " " ) + " " ) ; } var str = " " ; moveAllDigitAtBeginning ( str ) ;