function reverseWords(str) {
const allWords = str.split(" ")
return allWords.map(item => item.split("").reverse().join("")).join(" ")
}
function reverseWords(str) {
const allWords = str.split(" ")
return allWords.map(item => item.split("").reverse().join("")).join(" ")
}
const reverseString = (str = null) => {
let newStr = [];
let string = "";
let reverseStr = "";
for (i = 0; i < str.length; i++) {
if (str[i] == " ") {
newStr.push(string);
string = "";
} else {
string += str[i];
}
}
if (string) {
newStr.push(string);
}
for (i = newStr.length - 1; i >= 0; i--) {
reverseStr += newStr[i] + " ";
}
return reverseStr;
};
let val = reverseString("My name is mohd jagir");
console.log(val);
//output will be jagir mohd is name My