rcass
3/31/2018 - 10:57 PM

Reverse Words in the sentence and maintain order in sentence

Reverse Words in the sentence and maintain order in sentence

function reverseWords(str){
  if (!str || str.length < 2) return str;

  return str.split("").reverse().join("").split(" ").reverse().join(" ");
}

console.log(reverseWords("Hello how are you"));

// Returns "olleH woh era uoy"