Last active
July 31, 2021 10:56
-
-
Save deathlezz/7576eb97a9f17bb9bab2daea6a2df119 to your computer and use it in GitHub Desktop.
Compare elements in one array in Swift 5.
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
// | |
// Compare elements in one array | |
// | |
// Check if all elements in array are the same | |
let input = "aaaa" | |
let areSame = input.allSatisfy { $0 == input.last } | |
if areSame == false { | |
print("gooood") | |
} else { | |
print("bad input") | |
} | |
// Check the first and the last element | |
let input2 = " aaaa " | |
if input2.hasPrefix(" ") || input2.hasSuffix(" ") { | |
print("bad input") | |
} else { | |
print("gooood") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment