Here is the problem: Given a word, compute the scrabble score for that word.
I've created a dictionary to track the characters and their correlated Scrabble points. I made a function that iterates over each character in the dictionary array and if it contains the iterated character it adds a point. Unfortunately, the function doesn't tally up characters that are repeated and I can't seem to understand why...
// struct contains the Scrabble Points dictionary
struct Scrabble {
static let scrabblePoints = [1 : ["AEIOULNRST"],
2 : ["DG"],
3 : ["BCMP"],
4 : ["FHVWY"],
5 : ["K"],
8 : ["JX"],
10 : ["QZ"]]
}
var points = 0
// I can't figure out why my function doesn't iterate over repeated characters...
func pointGenerator(word:String) -> Int {
for (key, letters) in Scrabble.scrabblePoints {
for i in letters {
for j in i {
if word.contains(j) {
points += key
}
}
}
}
return points
}
//score is inaccurate.