Skip to content

Instantly share code, notes, and snippets.

@clc80
Created February 11, 2020 03:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clc80/e40cbe3e5e8258744ef8659c2bb4fa0d to your computer and use it in GitHub Desktop.
Save clc80/e40cbe3e5e8258744ef8659c2bb4fa0d to your computer and use it in GitHub Desktop.
Palindrome Swift Challenge
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