Write a function reverseBoth(sentence) that reverses a string in two ways and returns both results in an object { eachWord, whole }.
eachWord: the characters of every word are reversed, but the words stay in their order. 'Hello World' gives 'olleH dlroW'.whole: the whole string reversed character by character. 'Hello World' gives 'dlroW olleH'.'Hi!' gives '!iH'.eachWord every space stays where it is: double spaces, spaces at the start and spaces at the end too. The input has only spaces as whitespace, no tabs or line breaks.''.You can split the string into words and join them back, but keep every space.
reverseBoth('Hello World')Returns { eachWord: 'olleH dlroW', whole: 'dlroW olleH' }
reverseBoth('Hi Ann')Returns { eachWord: 'iH nnA', whole: 'nnA iH' }
Asked at JP Morgan · Source
reverseBoth('Hello World'){ eachWord: 'olleH dlroW', whole: 'dlroW olleH' }reverseBoth('I Love Java'){ eachWord: 'I evoL avaJ', whole: 'avaJ evoL I' }reverseBoth('Selenium'){ eachWord: 'muineleS', whole: 'muineleS' }Hidden tests run on Submit.