From c7d61f82e986688b557768ffb50f6ccdb458ce3f Mon Sep 17 00:00:00 2001 From: billalp Date: Fri, 1 Nov 2019 12:33:00 +0000 Subject: [PATCH] Working function --- palindromes/palindromes.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/palindromes/palindromes.js b/palindromes/palindromes.js index ccfda4b..49ee89b 100644 --- a/palindromes/palindromes.js +++ b/palindromes/palindromes.js @@ -1,5 +1,17 @@ -const palindromes = function() { +const palindromes = function(word) { + const wordArr = word.split(''); + const reversedArray = wordArr.reverse(); + newArray = []; + + for (var i = 0; i < wordArr.length; i++) { + if (wordArr[i] === reversedArray[i]) { + newArray.push(wordArr[i]) + } else { + newArray = ['Not a palindrome']; + } + } + return true ? newArray.join('') === word : false; } module.exports = palindromes