Last active
July 31, 2021 10:54
-
-
Save deathlezz/092789211e460315ba9264cbea0f9444 to your computer and use it in GitHub Desktop.
Find random element in 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
// | |
// Find random element in array | |
// | |
let array = "abcdefghijklmnopqrstuvwxyz" | |
let random = (0...3).compactMap { _ in array.randomElement() } // (0...3) - it means amount of characters | |
print(random) // ["f", "u", "y", "m"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment