-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pipes | tanisha | js-scrabble #33
base: master
Are you sure you want to change the base?
Conversation
JS ScrabbleWhat We're Looking For
|
score: function(word) { | ||
// TODO: implement score | ||
// TODO: implement score //score(word): returns the total score value for the given word. The word is input as a string (case insensitive). The chart below shows the point value for a given letter | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should remove TODOs once they're done
|
||
if (regex.test(word) != true) { | ||
throw 'Error'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments here. First, instead of writing != true
it would be more succinct to say if (!regex.test(word))
.
Second, you should provide a more detailed description of what went wrong. Error
by itself doesn't help much trying to debug.
for (let word of arrayOfWords) { | ||
wordScore = this.score(word); | ||
scores.push(wordScore); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This algorithm ends up being a little over-complicated. By my reading, your steps are:
- Calculate a score for every word
- Find those words that share the highest score
- Use apply tie-breaking logic to those words
A simpler algorithm is to iterate through the list of words, keeping track of the best word / score seen so far. For each word:
- If the current word has a higher score than the best word, it's the new best word
- If the best word has a higher score, keep it
- If the two are tied, apply tie-breaking logic, favoring the existing best word.
This single-pass approach is more concise and (in my opinion) easier to understand.
JS Scrabble
Congratulations! You're submitting your assignment!
Comprehension Questions
this
andself