Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
45
rated 0 times [  46] [ 1]  / answers: 1 / hits: 23577  / 9 Years ago, thu, january 21, 2016, 12:00:00

Looked around and could not find an answer for this one.



I am trying to reverse each word of a string without changing the order of the words...



this is the code I have:



  function wordsReverser(string){
return string.split('').reverse().join('');
}
console.log(wordsReverser('New string, same results.'));


what I am getting for results is this:
.stluser emas ,gnirts weN



I am looking for this:
weN gnirts...



Here is a jsbin


More From » arrays

 Answers
24

Try something like this.



function wordsReverser(string){
return string.split().reverse().join().split( ).reverse().join( )
}

console.log(wordsReverser('New string, same results.'));

[#63622] Tuesday, January 19, 2016, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gianni

Total Points: 307
Total Questions: 104
Total Answers: 96

Location: South Georgia
Member since Sun, Aug 8, 2021
3 Years ago
;