Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Schedule: 7 October 2005
Disscussion: 4 Answer a Midterm Review Question
Write a method findPalindrome: that takes as input a collection of strings, possible containing spaces, (e.g. #(‘2002’ ‘a man a plan a canal panama’ ‘george of the jungle’)) and returns just those strings that are palindromes, i.e., without spaces, the letters are the same forward and backward (for the example, #(‘2002’ ‘a man a plan a canal panama’) would be the correct return value). Some useful tips:
Strings understand reverse
string reject: [:ch | ch = Character space] will return string with spaces removed.
"finds the palindromes with in an array or strings"
| originals forwardString ReversedString |
originals := OrderedCollection new.
Strings do: [:originalString |
forwardString:=originalString reject: [:ch | ch = Character space].
(ReversedString compare: forwardString) ifTrue:[originals add: originalString]].
Links to this Page
- Michael Dunn last edited on 8 December 2005 at 6:58 pm by r38h150.res.gatech.edu
- Fall 2005 Discussion 4 last edited on 6 December 2005 at 3:45 pm by r36h51.res.gatech.edu