forked from AdaGold/js-scrabble
-
Notifications
You must be signed in to change notification settings - Fork 42
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
Mariko - Ampers #33
Open
marikoja
wants to merge
4
commits into
Ada-C9:master
Choose a base branch
from
marikoja:master
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
Mariko - Ampers #33
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1218a81
workd score code, passes test for correctly scoring simple words
marikoja 967abcb
code for alphanermic chekc, passes test fot throws on bad characters
marikoja 97f1c67
adds 50 to wordScore if word is 7 letters
marikoja 673e25e
completes code and tests for primary requirements, all tests passing
marikoja 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
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
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
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,16 +1,139 @@ | ||
|
||
const letterValues = { | ||
'A' : 1, | ||
'B' : 3, | ||
'C' : 3, | ||
'D' : 2, | ||
'E' : 1, | ||
'F' : 4, | ||
'G' : 2, | ||
'H' : 4, | ||
'I' : 1, | ||
'J' : 8, | ||
'K' : 5, | ||
'L' : 1, | ||
'M' : 3, | ||
'N' : 1, | ||
'O' : 1, | ||
'P' : 3, | ||
'Q' : 10, | ||
'R' : 1, | ||
'S' : 1, | ||
'T' : 1, | ||
'U' : 1, | ||
'V' : 4, | ||
'W' : 4, | ||
'X' : 8, | ||
'Y' : 4, | ||
'Z' : 10 | ||
}; | ||
|
||
const Scrabble = { | ||
|
||
// score: function(word) {} same as vv | ||
score(word) { | ||
word = word.toUpperCase(); | ||
|
||
}, | ||
highestScoreFrom(arrayOfWords) { | ||
let letterCheck = /^[A-Z]+$/; | ||
|
||
}, | ||
}; | ||
if (!letterCheck.test(word)) { | ||
throw 'Invalid characters'; | ||
} | ||
let letters = word.split(''); | ||
|
||
Scrabble.Player = class { | ||
let wordScore = 0 | ||
|
||
}; | ||
if (word.length > 7 || typeof word !== 'string' || word.length < 1) { | ||
throw 'Word is invlaid';} | ||
|
||
if (word.length === 7) { | ||
wordScore += 50 | ||
} | ||
|
||
for (let letter of letters) { | ||
for (let value in letterValues) { | ||
if (letter === value) { | ||
wordScore += letterValues[value] | ||
} | ||
} | ||
} | ||
|
||
return wordScore | ||
}, | ||
|
||
highestScoringWord(arrayOfWords) { | ||
if (arrayOfWords.length < 1 || !Array.isArray(arrayOfWords)){ | ||
throw 'No words to find high score'; | ||
} else if (arrayOfWords.length === 1) { | ||
return arrayOfWords[0]; | ||
} else { | ||
let highestWordScore = 0; | ||
let highestWord = ''; | ||
|
||
for (let i = 0; i < arrayOfWords.length; i++) { | ||
let currentWordScore = this.score(arrayOfWords[i]); | ||
|
||
if (currentWordScore > highestWordScore) { | ||
highestWordScore = currentWordScore; | ||
highestWord = arrayOfWords[i]; | ||
} else if (currentWordScore === highestWordScore); { | ||
if (highestWord.length !== 7 && (arrayOfWords[i].length === 7 || | ||
arrayOfWords[i].length < highestWord.length)) { | ||
highestWordScore = currentWordScore; | ||
highestWord = arrayOfWords[i]; | ||
} | ||
} | ||
} | ||
return highestWord; | ||
} | ||
}, | ||
|
||
highestWordScore(arrayOfWords) { | ||
return Scrabble.score(Scrabble.highestScoringWord(arrayOfWords)); | ||
}, | ||
|
||
}; | ||
|
||
Scrabble.Player = class { | ||
constructor(name) { | ||
this.name = name; | ||
if (name === undefined) { | ||
throw 'Players must have a name' | ||
} | ||
this.plays = []; | ||
} | ||
play(word) { | ||
|
||
if (word === undefined || typeof(word) !== 'string') { | ||
throw 'Invalid word' | ||
} | ||
|
||
if (this.hasWon()) { | ||
return false | ||
} else { | ||
this.plays.push(word); | ||
return true; | ||
} | ||
} | ||
|
||
hasWon() { | ||
if (this.totalScore() >= 100) { | ||
return true | ||
} else { | ||
return false | ||
} | ||
} | ||
|
||
totalScore() { | ||
let total = 0; | ||
|
||
for (let i = 0; i < this.plays.length; i++) { | ||
total += Scrabble.score(this.plays[i]); | ||
} | ||
return total; | ||
} | ||
|
||
}; | ||
|
||
|
||
module.exports = Scrabble; | ||
module.exports = Scrabble; |
Oops, something went wrong.
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.
These two methods should be in the
Scrabble.Player
class.