I made the ProgrammingLanguage
enum conform to the CaseIterable
protocol, giving me access to the type’s allCases
property. I iterator on the property’s collection of values and print their rawValue
property.
For the gold variation of this challenge, I use the shorthand syntax $0
to access the closure’s one argument. The map(_:)
instance method returns an array of the given argument’s type, and I pass the array as an argument to the print()
method.
// Electrum challenge
enum ProgrammingLanguage: String, CaseIterable {
case swift
case objectiveC = "objective-c"
case c
case cpp = "c++"
case java
}
for language in ProgrammingLanguage.allCases {
print(language.rawValue)
}
// Electrum gold challenge
print(ProgrammingLanguage.allCases.map({ $0.rawValue }))