I started learning Swift and functions, and I ran into a problem. Tell me how to understand the below code:
func genWallet (walletLength: Int) -> [Int] { let typesOfBanknotes = [50, 100, 200, 500] var wallet: [Int] = [] for _ in 1...walletLength { let randomIndex = Int( arc4random_uniform( UInt32( typesOfBanknotes.count - 1 ) ) ) wallet.append(typesOfBanknotes[randomIndex]) } return wallet } func sumWallet( banknotFunction wallet: (Int) -> ([Int]) ) -> Int? { let myWalletArray = wallet( Int( arc4random_uniform(10) ) ) var sum: Int = 0 for oneBanknote in myWalletArray { sum += oneBanknote } return sum } sumWallet(banknotFunction: genWallet) Why does sumWallet (banknotFunction: genWallet) work?
func genWallet (walletLength: Int) requires the same walletLength parameter at the input, but I do not specify it!
Where does the value of walletLength come from in this function?