forked from AdaGold/js-scrabble
-
Notifications
You must be signed in to change notification settings - Fork 44
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
Wave 1 #16
Open
jm-rives
wants to merge
8
commits into
Ada-C6:master
Choose a base branch
from
jm-rives:wave_1
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Wave 1 #16
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
308a8f0
ADD playword function
jm-rives c774a17
CHANGED fxn naming to be more semantic
jm-rives a68e81b
ADD letterScores hash
jm-rives 97ce137
ADD letterScores hash
jm-rives bc04cba
UPDATED module to use prototypes
jm-rives 94eed94
ADD empty highestScoreFrom function.
jm-rives 153bf17
ADD 50 pt bonus for 7 letter word
jm-rives 02d5063
CHECKPOINT wave 1 complete.
jm-rives File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,88 @@ | ||
'use strict'; | ||
|
||
var Scrabble = function() {}; | ||
|
||
// YOUR CODE HERE | ||
Scrabble.prototype.helloWorld = function() { | ||
return 'hello world!'; | ||
Scrabble.prototype.splitWord = function(word) { | ||
// add some data validation here later | ||
var wordString = word.toUpperCase(); | ||
var letterArray = Array.from(wordString); | ||
return letterArray; | ||
} | ||
|
||
Scrabble.prototype.score = function(word) { | ||
// pass in splitWord | ||
var letters = this.splitWord(word); | ||
var wordScore = 0; | ||
// loop over each element in letters | ||
for (var i = 0; i < letters.length; i++) { | ||
var letter = letters[i]; | ||
// assign a score to letter | ||
var score = this.letterScores[letter]; | ||
// add score to running total | ||
wordScore += score; | ||
|
||
} | ||
// return score for word | ||
return wordScore; | ||
|
||
} | ||
|
||
Scrabble.prototype.highestScoreFrom = function(arrayOfWords) { | ||
var highScore = 0; | ||
var highestScoringWord = null; // using 0 should I use null instead? | ||
|
||
for (var i = 0; i < arrayOfWords.length; i++) { | ||
|
||
var word = arrayOfWords[i]; | ||
var currentWordScore = this.score(word); | ||
|
||
if (currentWordScore == highScore){ | ||
if (word.length == 7 && highestScoringWord.length != 7){ | ||
highestScoringWord = word; | ||
// if there is a word that uses all seven tiles award that word an additional 50 pts | ||
highScore = currentWordScore + 50; | ||
// if there is a tie, prefer the highest scorring word made with the fewest tiles | ||
} else if (word.length < highestScoringWord.length) { | ||
highestScoringWord = word; | ||
highScore = currentWordScore; | ||
} | ||
} | ||
|
||
if (currentWordScore > highScore) { | ||
highScore = currentWordScore; | ||
highestScoringWord = word; | ||
} | ||
|
||
} | ||
return highestScoringWord; | ||
} | ||
|
||
|
||
// // chose to use object as these are not so much returning a actions as being acted upon | ||
// you need the semicolon for object literals | ||
Scrabble.prototype.letterScores = { | ||
A: 1, E: 1, I: 1, O: 1, U: 1, L: 1, N: 1, R: 1, S: 1, T: 1, | ||
D: 2, G: 2, | ||
B: 3, C: 3, M: 3, P: 3, | ||
F: 4, H: 4, V: 4, W: 4, Y: 4, | ||
K: 5, | ||
J: 8, X: 8, | ||
Q: 10, Z: 10 // NO SEMICOLON! | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very nice use of a JavaScript object as a hash! |
||
|
||
module.exports = Scrabble; | ||
var wordSeven = "jejunum"; | ||
var wordThree = "wee"; | ||
var oneScrabble = new Scrabble(); | ||
var arrayWords = ["Ty", "Bacon", "piecrust", "tea", "eiecrust"]; | ||
|
||
console.log(oneScrabble.score(wordSeven)); | ||
console.log(oneScrabble.score(wordThree)); | ||
console.log(oneScrabble.highestScoreFrom(arrayWords)); | ||
|
||
|
||
|
||
// var myScrabble = new Scrabble(); | ||
|
||
// do stuff here to test | ||
|
||
module.exports = Scrabble; // take the whole scrabble class so it can be used by other files (What do you want to be visible outside the module) |
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.
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.
Shouldn't the
score
function already count in the 50 point 7-letter-word bonus?