Skip to content

Instantly share code, notes, and snippets.

@ferlyz05
Created March 15, 2014 08:20
Show Gist options
  • Save ferlyz05/9563384 to your computer and use it in GitHub Desktop.
Save ferlyz05/9563384 to your computer and use it in GitHub Desktop.
var letters = [];
var rword = "";
putstr("Enter a sentence: ");
var sentence = readline();
var sword = "";
for (var i = 0; i < sentence.length; i++) {
if (sentence[i] == " ") {
;
}
else {
sword += sentence[i];
}
}
for (var i = 0; i < sword.length; i++) {
letters.push(sword[i]);
}
while (letters.length > 0) {
rword += letters.pop();
}
if (rword === sword) {
print(sentence + " is a palindrome.");
}
else {
print(sentence + " is not a palindrome.");
}
Here are a couple of runs of the new program:
Enter a sentence: a man a plan a canal panama
amanaplanacanalpanama is a palindrome.
Enter a sentence: now is the time for all good people
nowisthetimeforallgoodpeople is not a palindrome.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment