Reverse all the words of sentence JavaScript

We are required to write a JavaScript function that takes in a string and returns a new string which has all the words reversed from the original string.

For example −

If the original string is −

"Hello World how is it outside"

Then the output should be −

"olleH dlroW woH si ti edistuo"

Now, let's write the code for this function −


const str = 'Hello World how is it outside';
const reverseSentence = str => {
   const arr = str.split(" ");
   const reversed = => {
      return el.split('').reverse().join("");
   return reversed.join(" ");


The output in the console will be −

olleH dlroW woh si ti edistuo