freeCodeCamp/curriculum/challenges/chinese-traditional/02-javascript-algorithms-an.../basic-algorithm-scripting/reverse-a-string.md

1.0 KiB

id title challengeType forumTopicId dashedName
a202eed8fc186c8434cb6d61 反轉字符串 5 16043 reverse-a-string

--description--

請反轉傳入函數的字符串。

在反轉字符串之前,你可能需要將其切分成包含字符的數組。

函數的返回結果應爲字符串。

--hints--

reverseString("hello") 應返回一個字符串。

assert(typeof reverseString('hello') === 'string');

reverseString("hello") 應返回 olleh

assert(reverseString('hello') === 'olleh');

reverseString("Howdy") 應返回 ydwoH

assert(reverseString('Howdy') === 'ydwoH');

reverseString("Greetings from Earth") 應返回 htraE morf sgniteerG

assert(reverseString('Greetings from Earth') === 'htraE morf sgniteerG');

--seed--

--seed-contents--

function reverseString(str) {
  return str;
}

reverseString("hello");

--solutions--

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

reverseString("hello");