Skip to content

Instantly share code, notes, and snippets.

Created November 21, 2022 11:03
What would you like to do?
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment