EDIT: I'm not asking a function to count an occurence. I'm asking a function to count an occurence 2 by 2, 3 by 3, 10 by 10, etc... this is my problem
I have an array of scores, lets say:
[2,2,3,4,4,4,4,5,6,6,8,8,8,9,10,10]
I would like to have a function that transform this Array
into a Dictionary [Int: Int]()
to have something like that:
func groupArrayBy(array: Array<Int>, coef: Int) -> Array<Int, Int>{
// if coef = 2 -> 2 by 2, count occurence
// Transform the array to:
// [2: 3, 4: 5, 6: 2, 8: 4, 10: 2]
// return Dictionary
}
(With coef = 3, it would be: [2: 7, 5: 3, 8: 6]
-> 3 by 3)
I found nothing about that. Is it even possible ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…