Skip to content

Instantly share code, notes, and snippets.

@Hexer10
Created July 8, 2019 14:02
Show Gist options
  • Select an option

  • Save Hexer10/72e759429a071a9057124b3bf9ab1984 to your computer and use it in GitHub Desktop.

Select an option

Save Hexer10/72e759429a071a9057124b3bf9ab1984 to your computer and use it in GitHub Desktop.
void main() {
assert(identical(score(''), 0));
assert(identical(score('A'), 1));
assert(identical(score('AED'), 4));
assert(identical(score('DG'), 4));
assert(identical(score('BCMP'), 12));
assert(identical(score('QA'), 11));
}
int score(String str) {
int score = 0;
//Map declaration and definition
Map<List<String>, int> scrabbleDat = {
//list as a key and int as a value
['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T']: 1,
['D', 'G']: 2,
['B', 'C', 'M', 'P']: 3,
['F', 'H', 'V', 'W', 'Y']: 4,
['K']: 5,
['J', 'X']: 8,
['Q', 'Z']: 10
};
for (int i = 0; i < str.length; ++i) {
//Trying to access map based on the str parameter
//Adding the value returned to score variable
score += scrabbleDat[scrabbleDat.keys.firstWhere((list) => list.contains(str[i]))];
}
return score; // returning the score
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment