I want to reverse the words in a sentence (string) but keep the punctuation at the same place.
example: greetings! how are you today?
to result: today! you are how greetings?
So far I've done this but I can't really remember how should I approach the part with the punctuation. I thought of splitting like ('') this and looping and checking with regex but that looks like a daunting task. It would help a lot if you use my codeblock to upgrade rather than writing super complex functions of your own, after all I am new and I might not be able to read them lol.
let str = 'greetings! how are you today?'
let stringArr = ''
function strReverser(str) {
stringArr = str.split(' ').reverse().join(' ')
return stringArr
}
stringArr = strReverser(str)
console.log(stringArr)
strReverser(str)