Created
February 1, 2018 12:20
-
-
Save rizumita/1cf10df1b00d7140c9c3bffea6cbe794 to your computer and use it in GitHub Desktop.
for in vs reduce into
This file contains 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 range = 0..<10000000 | |
var i = false | |
test("for in") { | |
for n in range { | |
i = i || (n % 12345 == 0) | |
} | |
} | |
print(String(i)) | |
var j = false | |
test("reduce") { | |
j = range.reduce(into: false, { (flag, n) in | |
flag = flag || (n % 12345 == 0) | |
}) | |
} | |
print(String(j)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment