This code will not work, but here's the logic. See if you can get it working by fixing the
if statement:
- Read a string into variable
a and convert it to lowercase.
- Start a for-loop with the variable
i from 1 to the length of a.
- Extract the single character at position
i in string a using the string.sub function. If
it's not a space (~= " ") then concatenate the character to a new string called b.
- At the conclusion of the for-loop, variable
b contains a space-free version of the original string.
Now it's your turn. What condition would you put in the
if statement to see if b is equal to its reverse? This
is the "palindrome test."
Here are some test words (see Wikipedia): civic, radar, level, rotor, kayak, reviver, racecar, redder, madam, toot, boob, malayalam, pop, noon, and refer.
Here are some test phrases (Wikipedia): "Was it a rat I saw" or "Never odd or even"