Last active
May 4, 2018 00:16
-
-
Save briancordanyoung/3148d079b87f8b7ba65cf11c14d9d014 to your computer and use it in GitHub Desktop.
Rough, get values of characters
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
import Cocoa | |
// a = 97 | |
// z = 122 | |
let value = UInt8(ascii: "z") | |
extension Character { | |
var testValues: UInt8? { | |
guard let scaler = self.unicodeScalars.first else { return .none} | |
let value = UInt8(ascii: scaler) | |
return value - 96 | |
} | |
} | |
// "quarter".reduce(0, {sum, character in | |
// sum + character.testvalues | |
// }) | |
// | |
var sum: UInt8 = 0 | |
for character in "happy" { | |
if let charValue = character.testValues { | |
sum = sum + charValue | |
} | |
} | |
sum | |
//"quarter".reduce | |
// quarter | |
// happy |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment