4.0 KiB
4.0 KiB
id, title, isRequired, challengeType, forumTopicId, localeTitle
id | title | isRequired | challengeType | forumTopicId | localeTitle |
---|---|---|---|---|---|
aaa48de84e1ecc7c742e1124 | Palindrome Checker | true | 5 | 16004 | Palindrome Checker |
Description
true
если данная строка является палиндром. В противном случае верните false
. Палиндром - это слово или предложение, которое написано одинаково как вперед, так и назад, игнорируя знаки препинания, случай и интервал. Заметка Вам нужно будет удалить все небуквенные символы (знаки препинания, пробелы и символы) и превратить все в один и тот же случай (нижний или верхний регистр), чтобы проверить палиндромы. Мы будем передавать строки с различными форматами, такими как
"racecar"
, "RaceCar"
и "race CAR"
среди других. Мы также передадим строки со специальными символами, такими как "2A3*3a2"
, "2A3 3a2"
и "2_A3*3#A2"
. Не забудьте использовать Read-Search-Ask, если вы застряли. Напишите свой собственный код.
Instructions
Tests
tests:
- text: <code>palindrome("eye")</code> should return a boolean.
testString: assert(typeof palindrome("eye") === "boolean");
- text: <code>palindrome("eye")</code> should return true.
testString: assert(palindrome("eye") === true);
- text: <code>palindrome("_eye")</code> should return true.
testString: assert(palindrome("_eye") === true);
- text: <code>palindrome("race car")</code> should return true.
testString: assert(palindrome("race car") === true);
- text: <code>palindrome("not a palindrome")</code> should return false.
testString: assert(palindrome("not a palindrome") === false);
- text: <code>palindrome("A man, a plan, a canal. Panama")</code> should return true.
testString: assert(palindrome("A man, a plan, a canal. Panama") === true);
- text: <code>palindrome("never odd or even")</code> should return true.
testString: assert(palindrome("never odd or even") === true);
- text: <code>palindrome("nope")</code> should return false.
testString: assert(palindrome("nope") === false);
- text: <code>palindrome("almostomla")</code> should return false.
testString: assert(palindrome("almostomla") === false);
- text: <code>palindrome("My age is 0, 0 si ega ym.")</code> should return true.
testString: assert(palindrome("My age is 0, 0 si ega ym.") === true);
- text: <code>palindrome("1 eye for of 1 eye.")</code> should return false.
testString: assert(palindrome("1 eye for of 1 eye.") === false);
- text: '<code>palindrome("0_0 (: /-\ :) 0-0")</code> should return true.'
testString: 'assert(palindrome("0_0 (: /-\ :) 0-0") === true);'
- text: <code>palindrome("five|\_/|four")</code> should return false.
testString: assert(palindrome("five|\_/|four") === false);
Challenge Seed
function palindrome(str) {
// Good luck!
return true;
}
palindrome("eye");
Solution
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;
}