Last active
May 4, 2018 23:06
-
-
Save robtimp/c326fd7272bb2ab9976fff4d70db2afd to your computer and use it in GitHub Desktop.
Updated for Swift 4
This file contains hidden or 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
struct NoteSpeller { | |
static let wordURL = "https://raw.githubusercontent.com/dwyl/english-words/master/words.txt" | |
static let delimiter: Character = "\n" | |
static let notesNames: [Character] = ["a", "b", "c", "d", "e", "f", "g"] | |
static func getWords(includeH: Bool = false) -> [String] { | |
var notes = notesNames | |
if includeH { | |
notes.append("h") | |
} | |
guard let url = URL(string: wordURL), | |
let file = try? String(contentsOf: url) else { | |
return [] | |
} | |
let words = file.split(separator: delimiter).map { String($0) } | |
let result = words.filter { word in | |
for character in word { | |
if !notes.contains(character) { | |
return false | |
} | |
} | |
return true | |
} | |
return result | |
} | |
} | |
NoteSpeller.getWords() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment