Created
March 15, 2014 08:20
-
-
Save ferlyz05/9563384 to your computer and use it in GitHub Desktop.
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
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