Skip to content

Instantly share code, notes, and snippets.

@TarasShu
Created July 16, 2020 10:37
Show Gist options
  • Save TarasShu/cbfff56b21f0912651daf71c96d5ddf4 to your computer and use it in GitHub Desktop.
Save TarasShu/cbfff56b21f0912651daf71c96d5ddf4 to your computer and use it in GitHub Desktop.
func isStrangePair(_ str1: String, _ str2: String) -> Bool {
if str1.index(after: str1.startIndex) == str2.index(before: str2.endIndex)
&&
str1.index(before: str1.endIndex) == str2.index(after: str2.startIndex)
{
return true
} else {
return false
}
func isStrangePair(_ str1: String, _ str2: String) -> Bool {
if str1.prefix(1) == str2.suffix(1)
&&
str1.suffix(1) == str2.prefix(1)
{
return true
} else if str1.isEmpty || str2.isEmpty {
return false
} else {
return false
}
}
isStrangePair("sparkling", "groups") //➞ true
//
isStrangePair("bush", "hubris") //➞ false
//
isStrangePair("", "") //➞ true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment