Last active
October 10, 2018 04:41
-
-
Save Nicknyr/077b2b827720ccd5e2867e64d252cc0b to your computer and use it in GitHub Desktop.
Javascript Palindrone Function - Iterative approach w/ for loops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isPalindrone(word) { | |
let lettersCounter = 1; | |
for(let i = 0; i < word.length; i++) { | |
if(word[i] == word[word.length - lettersCounter]) { | |
lettersCounter++; | |
if (lettersCounter == word.length) { | |
return true; | |
} | |
} | |
else { | |
return false; | |
} | |
} | |
} | |
console.log(isPalindrone('racecar')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment