Created
September 3, 2017 17:58
-
-
Save jochri3/7eb5d78ecd21aef65d82e52df38bdb22 to your computer and use it in GitHub Desktop.
null created by ChrisLis - https://repl.it/HaKw/34
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
// Write a function that takes a string and returns true if it is a | |
// palindrome. A palindrome is a string that is the same whether written | |
// backward or forward. Assume that there are no spaces; only lowercase | |
// letters will be given. | |
// | |
// Difficulty: easy. | |
function is_palindrome(string) { | |
var contraire=string.split("").reverse().join(""); | |
if(contraire==string) | |
{ | |
return true | |
} | |
else | |
{ | |
return false | |
} | |
} | |
// These are tests to check that your code is working. After writing | |
// your solution, they should all print true. | |
console.log("\nTests for //palindrome?") | |
console.log("===============================================") | |
console.log('is_palindrome("abc") == false: ' + (is_palindrome('abc') === false)); | |
console.log('is_palindrome("abcba") == true: ' + (is_palindrome('abcba') === true)); | |
console.log('is_palindrome("z") == true: ' + (is_palindrome('z') === true)); | |
console.log("===============================================") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment