Open dorseysen opened 5 years ago
// 2019-10-08:单词原位反转
// 难度 ★
// 'I am dorsey' => 'I ma yesrod'
// the first solution 较为直观但性能较差
const situReverse_0 = str => str.split(' ').map(item => item.split('').reverse().join('')).join(' ');
console.log(situReverse_0('I am dorsey'));
// the second solution 较为巧妙且性能更好
const situReverse = str => str.split(' ').reverse().join(' ').split('').reverse().join('');
return situReverse('I am dorsey');
2019-10-08:单词原位反转 难度 ★ 'I am dorsey' => 'I ma yesrod'