Created
September 23, 2014 20:58
-
-
Save stuffmc/5cd2b25b35fddf8d1d37 to your computer and use it in GitHub Desktop.
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 bytes = [84,11] | |
// Imperative — 6 lines but more readable | |
var hex = "" | |
for byte in bytes { | |
let format = NSString(format: "%02x", byte) | |
hex = "\(hex)\(format)" | |
} | |
hex | |
// Functionnal - 4 lines but weird | |
bytes.map({ (byte: Int) -> String in | |
return NSString(format: "%02x", byte) | |
}).reduce("", combine: { (hex, byte) -> String in | |
return hex+byte | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment