import UIKit
/*
Your challenge is this: 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.
*/
let f = { (array: [Int]?) -> Int in array?.randomElement() ?? Int.random(in: 1...100) }
print(f([1, 2, 3]))
print(f(Array<Int>()))
print(f(nil))
No comments:
Post a Comment