Reverse word in sentence e.g. sky is blue should become blue is sky
Code:
let sentence="sky is blue";
let reversed = sentence.split(' ').reverse().join(' ')
console.log("Reversed:",reversed)
Output:
Reversed: blue is sky
Explanation:
First split sentence based on spacee,then reverse then join with space.
No comments:
Post a Comment