Search Your Question

Write a program to define closure, which take string, return integer

Ans : 

Write a closure that accepts string and return length of string :


 let simpleClosure:(String) -> (Int) = { name in
     return name.count
 }

 let result = simpleClosure("Hello, World")

 print(result




No comments:

Post a Comment