let str = "Today is Friday";
str = ' ' + str
var length = str.length;
var newStr=''
var last=length
for (let i = length - 1; i >= 0; i--) {
if(str[i]==' '){
newStr = newStr + ' ' + str.substring(i,last).trim()
last = i
}
}
console.log(newStr.trim())
Output:
Friday is Today
No comments:
Post a Comment