Blog

JavaScript Function(s) that Deal with Palindromes
Posted on June 17, 2015 in Algorithms, JavaScript by Matt Jennings

// Check if a string is a palindrome
function palindromeCheck(palindrome) {
	var arr = palindrome.split("");

	var reverseArr = arr.reverse();

	var reverseArrJoin = reverseArr.join("");

	if(palindrome == reverseArrJoin) {
  		return true;
	}
	else {
  		return false;
	}
}

// Output is "true" as "civic" is a palindrome
console.log(palindromeCheck("civic"));

Leave a Reply