File tree Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Expand file tree Collapse file tree 2 files changed +4
-10
lines changed Original file line number Diff line number Diff line change @@ -5,11 +5,7 @@ public func palindromeCheck(text: String?) -> Bool {
55 let mutableText = text. trimmingCharacters ( in: NSCharacterSet . whitespaces) . lowercased ( )
66 let length : Int = mutableText. characters. count
77
8- guard length >= 1 else {
9- return false
10- }
11-
12- if length == 1 {
8+ if length == 1 || length == 0 {
139 return true
1410 } else if mutableText [ mutableText. startIndex] == mutableText [ mutableText. index ( mutableText. endIndex, offsetBy: - 1 ) ] {
1511 let range = Range < String . Index > ( mutableText. index ( mutableText. startIndex, offsetBy: 1 ) ..< mutableText. index ( mutableText. endIndex, offsetBy: - 1 ) )
@@ -31,6 +27,8 @@ palindromeCheck(text: "Race fast Safe car")
3127// Test to check that palindromes are found regardless of case:
3228palindromeCheck ( text: " HelloLLEH " )
3329
30+ palindromeCheck ( text: " moom " )
31+
3432// Test that nil and empty Strings return false:
3533palindromeCheck ( text: " " )
3634palindromeCheck ( text: nil )
Original file line number Diff line number Diff line change @@ -5,11 +5,7 @@ public func palindromeCheck(text: String?) -> Bool {
55 let mutableText = text. trimmingCharacters ( in: NSCharacterSet . whitespaces) . lowercased ( )
66 let length : Int = mutableText. characters. count
77
8- guard length >= 1 else {
9- return false
10- }
11-
12- if length == 1 {
8+ if length == 1 || length == 0 {
139 return true
1410 } else if mutableText [ mutableText. startIndex] == mutableText [ mutableText. index ( mutableText. endIndex, offsetBy: - 1 ) ] {
1511 let range = Range < String . Index > ( mutableText. index ( mutableText. startIndex, offsetBy: 1 ) ..< mutableText. index ( mutableText. endIndex, offsetBy: - 1 ) )
You can’t perform that action at this time.
0 commit comments