From 0f5ead937448db11926a5c16048e45b82121e73b Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Wed, 6 Sep 2023 15:53:27 +0500 Subject: [PATCH] Update index_extra.js learning --- session1/index_extra.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/session1/index_extra.js b/session1/index_extra.js index e74879a..ff1fc7f 100644 --- a/session1/index_extra.js +++ b/session1/index_extra.js @@ -41,13 +41,28 @@ function reverseString(str) { // by Gamze Erol // return [...str].reverse().join(''); // ================= - + } // CHALLENGE 2: VALIDATE A PALINDROME // Return true if palindrome and false if not // ex. isPalindrome('racecar') === 'true', isPalindrome('hello') == false + +// ========================================= + // CONTRIBUTED SOLUTION + // by Ijaz Khan +// function isPalindrome(arr) { +// let strArr = [...arr].reduce((str, current, arrIndex, array) => { +// return str + array[array.length - arrIndex - 1]; +// }, ""); +// return strArr === arr; +// } +// console.log(isPalindrome("racecar")); + +// ================================== + + function isPalindrome(str) { // CONTRIBUTED SOLUTION // let isPali = true;