Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement