2016-08-16 17 views

答えて

2
let a = ["Swift","iOS", "Parse"] 
let b = ["Swift", "iOS", "Parse"] 
let c = ["iOS", "Parse"] 
let d = ["Parse"] 

var dictionary = [String: Int]() 

for value in a+b+c+d { 
    let index = dictionary[value] ?? 0 
    dictionary[value] = index + 1 
} 

let result = dictionary.sort{$0.1 > $1.1}.map{$0.0} 
print(result) 
//["Parse", "iOS", "Swift"] 

a = ["Swift","iOS", "Parse"] 
b = ["Swift", "iOS", "Parse"] 
c = ["iOS", "Parse"] 
d = ["Parse"] 

let bigArray:[String] = a+b+c+d 

がどのように私は繰り返しなしでほとんどの少なくともに周波数によって並べ替えられ、それが印刷されbigArrayから新しい配列を作成することができます

関連する問題