Last active
February 11, 2020 04:21
-
-
Save chadparker/202e06bbdc92ef2d3d58751166feeef3 to your computer and use it in GitHub Desktop.
Revisions
-
chadparker revised this gist
Feb 11, 2020 . 1 changed file with 13 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -39,3 +39,16 @@ canBePalindrome("A man, a plan, a can ... na canal panama.") //} else { // //odd //} // trying my own string reversing function: func reversedString(_ string: String) -> String { var reversedString = "" for character in string { reversedString.insert(character, at: reversedString.startIndex) } return reversedString } reversedString("reversed string") -
chadparker revised this gist
Feb 11, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -25,6 +25,7 @@ canBePalindrome("a") // should return true canBePalindrome("aa") // should return true canBePalindrome("hannah") // should return true canBePalindrome("abc") // should return false canBePalindrome("Racecar") canBePalindrome("A man, a plan, a can ... na canal panama.") -
chadparker revised this gist
Feb 11, 2020 . 1 changed file with 9 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -5,12 +5,14 @@ import Foundation // check from each end of the string // deal with even or odd amount of characters func canBePalindrome(_ string: String) -> Bool { var preparedString = string.lowercased() // remove spaces, common punctuation preparedString = preparedString.filter { $0 != " " } preparedString = preparedString.filter { $0 != "." } preparedString = preparedString.filter { $0 != "," } print(preparedString) return preparedString == String(preparedString.reversed()) } @@ -23,7 +25,10 @@ canBePalindrome("a") // should return true canBePalindrome("aa") // should return true canBePalindrome("hannah") // should return true canBePalindrome("abc") // should return false canBePalindrome("A man, a plan, a can ... na canal panama.") // I was starting with something like this, until I realized I could just reverse the whole string: //let stringBeginning = "" //let stringEnd = "" -
chadparker created this gist
Feb 11, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ import Foundation // Requirements: // ignore case, whitespace, and punctuation // check from each end of the string // deal with even or odd amount of characters // amanaplan func canBePalindrome(_ string: String) -> Bool { // prepare the string let preparedString = string.lowercased() return preparedString == String(preparedString.reversed()) } // Test Cases canBePalindrome("tacocat") // should return true canBePalindrome("daily") // should return false canBePalindrome("a") // should return true canBePalindrome("aa") // should return true canBePalindrome("hannah") // should return true canBePalindrome("abc") // should return false //let stringBeginning = "" //let stringEnd = "" //if preparedString.count % 2 == 0 { // //even // for letter in //} else { // //odd //}