You just need to group your array elements and use map to join your keys using joined(separator: ", ")
:
extension Array {
func group(of n: IndexDistance) -> Array<Array> {
return stride(from: 0, to: count, by: n)
.map { Array(self[$0..<Swift.min($0+n, count)]) }
}
}
Testing:
let dic = ["f":1,"a":1,"b":1,"c":1,"d":1,"e":1, "g": 1]
let arr = Array(dic.keys).group(of: 2).map{
$0.joined(separator: ", ")
}
arr //["b, a", "c, f", "e, g", "d"]
5
solved Add every 100 string keys from dictionary in array of strings with comma separator