Skip to content
This repository was archived by the owner on Sep 8, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions 002-palindrome/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,15 @@ const palindrome2 = (str) => {
return str.split('').every((char, index) => char === str[str.length - index - 1]);
};

// Solution 3
const palindrome3 = (str) => {
for (let i = 0, j = str.length - 1; i < j; ++i, --j) {
if (str[i] !== str[j]) {
return false;
}
}
return true;
};

const palindrome = palindrome2;
module.exports = palindrome;