Last active
September 25, 2017 00:15
-
-
Save koher/f9b86143c3e337e181450c79fce3441e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let array = [2, 3, 3, 4, 7, 2, 1, 4, 0, 9, 1, 2] | |
// array の要素の値ごとに集計 | |
// 2 が 3 個、 3 が 2 個 などを知りたい | |
var nToCount = [Int: Int]() | |
for n in array { | |
nToCount[n, default: 0] += 1 | |
} | |
// 結果を表示 | |
for (n, count) in (nToCount.sorted { $0.key < $1.key }) { | |
print("\(n): \(count)") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment