如何在Node Js环境中颠倒句子

时间:2018-12-31 18:04:06

标签: javascript 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"

These are the instructions

My code starts at Line 15 and I'm not sure what all the other code means

With the output i'm not sure why I'm not getting the right answers

1 个答案:

答案 0 :(得分:0)

您正在使用\b,它将“ w'w”分割为w ' w

更好的方法是使用space进行拆分。

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

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