Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

2.5 KiB
Raw Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
aaa48de84e1ecc7c742e1124 回文检查器 5 16004 palindrome-checker

--description--

如果传入的字符串是回文字符串,则返回 true,否则返回 false

Palindrome回文,指在忽略标点符号、大小写和空格的前提下,正着读和反着读一模一样。

注意:检查回文时,你需要先去除所有非字母数字的字符(标点、空格和符号),并将所有字母都转换成大写或都转换成小写。

我们会传入不同格式的字符串,例如:"racecar""RaceCar""race CAR" 等等。

我们也会传入一些包含特殊符号的字符串,例如 "2A3*3a2""2A3 3a2""2_A3*3#A2"

--hints--

palindrome("eye") 应返回一个布尔值。

assert(typeof palindrome('eye') === 'boolean');

palindrome("eye") 应返回 true。

assert(palindrome('eye') === true);

palindrome("_eye") 应返回 true。

assert(palindrome('_eye') === true);

palindrome("race car") 应返回 true。

assert(palindrome('race car') === true);

palindrome("not a palindrome") 应返回 false。

assert(palindrome('not a palindrome') === false);

palindrome("A man, a plan, a canal. Panama") 应返回 true。

assert(palindrome('A man, a plan, a canal. Panama') === true);

palindrome("never odd or even") 应返回 true。

assert(palindrome('never odd or even') === true);

palindrome("nope") 应返回 false。

assert(palindrome('nope') === false);

palindrome("almostomla") 应返回 false。

assert(palindrome('almostomla') === false);

palindrome("My age is 0, 0 si ega ym.") 应返回 true。

assert(palindrome('My age is 0, 0 si ega ym.') === true);

palindrome("1 eye for of 1 eye.") 应返回 false。

assert(palindrome('1 eye for of 1 eye.') === false);

palindrome("0_0 (: /-\ :) 0-0") 应返回 true。

assert(palindrome('0_0 (: /- :) 0-0') === true);

palindrome("five|\_/|four") 应返回 false。

assert(palindrome('five|_/|four') === false);

--seed--

--seed-contents--

function palindrome(str) {
  return true;
}



palindrome("eye");

--solutions--

function palindrome(str) {
  var string = str.toLowerCase().split(/[^A-Za-z0-9]/gi).join('');
  var aux = string.split('');
  if (aux.join('') === aux.reverse().join('')){
    return true;
  }

  return false;
}