/** * @param {string} s * @return {string} */ var reverseWords = function(s) { let splitS = s.split(" "); let reversedS = []; for (let i =0 ; i in splitS; i ++){ reversedS.push(splitS[i].split("").reverse().join("")) } return reversedS.join(" ") };
/** * @param {string} s * @return {string} */ var reverseWords = function(s) { let reversedS ; for (let ele of s.split(' ')){ ele = reverseWord(ele) if (!reversedS){ reversedS = ele; }else{ reversedS += ' ' + ele; } } return reversedS };
functionreverseWord(word){ let s = word.split(''); let reversedWord = ''; for (let i = 0; i < Math.floor(s.length / 2); i++) { temp = s[i]; s[i] = s[s.length - i - 1]; s[s.length - i - 1] = temp; } for (let i of s){ reversedWord += i; } return reversedWord; }