pipes | tanisha | js-scrabble #33
Open
tanham wants to merge 5 commits into
Open
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.
You should remove TODOs once they're done
|
|
||
| if (regex.test(word) != true) { | ||
| throw 'Error'; | ||
| } |
There was a problem hiding this comment.
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.
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JS Scrabble
Congratulations! You're submitting your assignment!
Comprehension Questions
thisandself