You want to write a Swift function that accepts a variadic list of integers and returns a dictionary where keys are the integers and values are their squares. Which function correctly implements this?
hard📝 Application Q8 of 15
Swift - Functions
You want to write a Swift function that accepts a variadic list of integers and returns a dictionary where keys are the integers and values are their squares. Which function correctly implements this?
Afunc squares(_ nums: Int...) -> [Int: Int] {
var dict = [Int: Int]()
for n in nums {
dict.append(n * n)
}
return dict
}