JavaScript program to implement the above approach
function rev ( str ) { var st = 0 ; var ed = str . length - 1 ; var s = str . split ( " " ) ; while ( st < ed ) { var temp = s [ st ] ; s [ st ] = s [ ed ] ; s [ ed ] = temp ; st ++ ; ed -- ; } return s . join ( ) ; } function check ( a , b , n ) { var i = 0 ; var j = n - 1 ;