Skip to content

Instantly share code, notes, and snippets.

@EvolvingParty
Created November 21, 2022 11:03
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 EvolvingParty/7e58cdd20adb8e22158ac0c1805f5652 to your computer and use it in GitHub Desktop.
Save EvolvingParty/7e58cdd20adb8e22158ac0c1805f5652 to your computer and use it in GitHub Desktop.
DAY 14. 100 Days of SwiftUI – Hacking with Swift. Checkpoint 9
import Cocoa
/// Write a function that accepts an optional array of integers, and returns one randomly. If the array is missing or empty, return a random number in the range 1 through 100.
/// Write this whole thing in one line of code
func pickANumber(from: [Int]? = nil) -> Int {
from?.randomElement() ?? Int.random(in: 1...100)
}
let newNuber = pickANumber()
print(newNuber)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment