I am trying to find out the count of first and last name value exit in an array of a and return a result as[String: Int] a count with the same key.
I am getting error on this line newResult[arg.key] = counts . Cannot assign value of type 'Int' to type 'Int?
func abbreviation(a:[String], b: [String : String]) ->[String : Int] { let dict = b.reduce([String : Int]()){ (result, arg) in var newResult = result let counts = a.reduce(0) { (newcount, value) -> Int in let count = newcount + (value.components(separatedBy:arg.value).count - 1) return count } return newResult[arg.key] = counts } return dict } //result
let dict = abbreviation(a:["This is chandan kumar and chandan kumar and new chandan","check chandan kumar","non ame"], b:["first":"chandan","last":"kumar"])
abbreviation?