/**
* @param {string} s
* @return {string}
*/
var reverseWords = function(s) {
return s.split(' ')
.filter(str => str) // empty strings are falsy
.reverse()
.join(' ');
}
/**
* @param {string} s
* @return {string}
*/
var reverseWords = function(s) {
let returnString = "";
let arraySplit = s?.trim()?.split(" ")?.reverse();
for (let i = 0; i < arraySplit.length; i++) {
if (arraySplit[i] !== "") {
returnString += arraySplit[i] + (i < arraySplit.length - 1 ? " " : "");
}
}
console.log(returnString);
return returnString
}