📜  js 反转奇数长度的单词 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:47.259000             🧑  作者: Mango

代码示例1
// Reverse the Odd Length Words
function reverseOdd(str) {
  return str.split(" ").map(w => w.length%2 ? [...w].reverse().join("") : w).join(" ");
}

console.log(reverseOdd("Bananas"));    // "sananaB"
console.log(reverseOdd("One two three four"));    // "enO owt eerht four"