From 8be7d8327ace97eecc7f75368b48a7b3287f54ac Mon Sep 17 00:00:00 2001 From: taras-d Date: Sun, 19 Aug 2018 20:36:56 +0300 Subject: [PATCH] Palindrome for-loop solution --- 002-palindrome/index.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/002-palindrome/index.js b/002-palindrome/index.js index 1a2c6b0..9116922 100644 --- a/002-palindrome/index.js +++ b/002-palindrome/index.js @@ -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;