Skip to content

Instantly share code, notes, and snippets.

@nielslange
Last active March 28, 2019 03:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nielslange/f84ddb5fae4db5af1f41997304dfdb13 to your computer and use it in GitHub Desktop.
Save nielslange/f84ddb5fae4db5af1f41997304dfdb13 to your computer and use it in GitHub Desktop.
Check if give string is a palindrom
function isPalindrom(string) {
var palindrom = true;
for ( i = 0; i < (string.length / 2); i++ ) {
if ( string.charAt(i) != (string.charAt(string.length - i - 1)) ) {
palindrom = false;
break;
}
}
if ( palindrom ) {
console.log(string + ' is a palindrom');
} else {
console.log(string + ' is not a palindrom');
}
}
isPalindrom('radar');
isPalindrom('radars');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment