Monday, July 1, 2024

🎉 I just finished Day 14 of the #100DaysOfSwiftUI at https://www.hackingwithswift.com/100/swiftui/14

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

🎉 I just finished Day 19 of the #100DaysOfSwiftUI at https://www.hackingwithswift.com/100/swiftui/19

 Made a Temperature Converter App for the SwiftUI Challenge Day!