首页 > 解决方案 > 如何在 Node Js 环境中反语句

问题描述

I'm doing a practice coding problem and my code doesn't work in this particular environment, how do I get my code work and print multiple lines of sentences backwards. My code starts at "Line 15"

这些是说明

我的代码从第 15 行开始,我不确定所有其他代码的含义

有了输出,我不确定为什么我没有得到正确的答案

标签: javascriptnode.js

解决方案


您正在使用\bwhich 会将“w'w”拆分为w ' w.

更好的方法是使用space.

function reverse(input){
  return input.split(' ').reverse().join(' ');
}

console.log(reverse('Hello world'));
console.log(reverse('Hello world 123'));


推荐阅读