Skip to content

Instantly share code, notes, and snippets.

@MarmaladeKnight
Created February 13, 2021 15:00
Show Gist options
  • Save MarmaladeKnight/7b9a4d9092460c60fb6ff6c8af07a18d to your computer and use it in GitHub Desktop.
Save MarmaladeKnight/7b9a4d9092460c60fb6ff6c8af07a18d to your computer and use it in GitHub Desktop.
#1 Task
//JS
function preparePhrase(phrase) {
return phrase.toLocaleLowerCase()
.replace(/[^0-9а-яa-z]/gi, "");
}
function isPalendrome(phrase) {
const preparedPhrase = preparePhrase(phrase);
for (let i = 0, j = preparedPhrase.length - 1; i < j; i++, j--) {
if (preparedPhrase[i] !== preparedPhrase[j])
return false;
}
return true;
}
function isPalendromeLazy(phrase) {
const preparedPhrase = preparePhrase(phrase);
return preparedPhrase === preparedPhrase.split('').reverse().join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment