Week 14 Algorithm Hacks
x = "racecar"
#function for the checker (takes in a word parameter)
def check_palindrome(word):
#loops through the word
for i in range(len(word)//2):
if word[i] != word[len(word)-i-1]:
return False
return True
print(check_palindrome(x))
// plaindrome checker (in javascript this time)
// function that takes any string as a parameter
function checkPalindrome(string) {
// find the length of a string
const len = string.length;
// loop through half of the string
for (let i = 0; i < len / 2; i++) {
// check if first and last string are same
if (string[i] !== string[len - 1 - i]) {
return false;
}
}
return true;
}
string = "racecar"
// calls the function
value = checkPalindrome(string);
console.log(value);