Created
February 11, 2020 03:15
-
-
Save clc80/e40cbe3e5e8258744ef8659c2bb4fa0d to your computer and use it in GitHub Desktop.
Palindrome Swift Challenge
This file contains 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 characters
import UIKit | |
func canBePalindrome(string: String) -> Bool { | |
//lowercase the string | |
string.lowercased() | |
//Reverse it in a new string | |
let newString = String(string.reversed()) | |
//compare the values | |
if string == newString{ | |
return true | |
}else { | |
return false | |
} | |
} | |
print(canBePalindrome(string: "tacocat")) // returns true | |
print(canBePalindrome(string: "daily")) // returns false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment