Untitled

mail@pastecode.io avatar
unknown
swift
3 years ago
512 B
1
Indexable
Never
var animals = [
"mammals":["cat", "dog", "wolf"],
"neognaths":["lark", "tit", "sparrow"],
"amphibians": ["lizard", "snake", "frog"]
]
 
func bestAnimals(_ a: [String: [String]]) -> [String] {
    var result = [String]()
    for (_, val) in a.enumerated() {
        var c = a[val.key]!
        for ind in c.indices {
            var an = c[ind]
            if an.count > 3 {
                result.append(an)
                result = result.sorted(by: >)
            }
        }
    }
    return result.sorted()
}