reverse given text words only input is "one two three four" output new string is "eno owt eerht ruof "


reverse given text words only input is "one two three four" output new string is "eno owt eerht ruof "

Following is sample javascript code.

function reverceWords(str){
  const arr = str.split(' ');
  let currentString = ''
  for(let i=0; i<arr.length;i++) {
  	
    const newVal = arr[i].split('')
    for(let j=newVal.length-1; j>= 0;  j -- ){
    	currentString += j === 0 ? newVal[j]+" " : newVal[j]
    }
	
  }
  return currentString
}

input::
console.log(reverceWords("one two three four"))

output::
"eno owt eerht ruof"