Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save briancordanyoung/3148d079b87f8b7ba65cf11c14d9d014 to your computer and use it in GitHub Desktop.
Save briancordanyoung/3148d079b87f8b7ba65cf11c14d9d014 to your computer and use it in GitHub Desktop.
Rough, get values of 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