Reverse the Words of a String using Stack | Function to reverse the words of the given sentence ; Create an empty character array stack ; Push words into the stack ; Get the words in reverse order ; Driver code
function reverse ( k ) { let s = [ ] ; let token = k . split ( " " ) ; for ( let i = 0 ; i < token . length ; i ++ ) { s . push ( token [ i ] ) ; } while ( s . length > 0 ) { document . write ( s [ s . length - 1 ] + " " ) ; s . pop ( ) ; } } let k = " " ; reverse ( k ) ;