Skip to content
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
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ There are many possible answers to this question, but according to the tests the
### Primary Requirements
Create the following methods within the `Scrabble` object.
- `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.
- `highestScoreFrom(arrayOfWords)`: returns **the word in the array with the highest score**.
- `highestScoringWord(arrayOfWords)`: returns **the word in the array with the highest score**.
- Note that it’s better to use fewer tiles, so if the top score is tied between multiple words, pick the one with the fewest letters.
- Note that there is a bonus (50 points) for using all seven letters. If the top score is tied between multiple words and one used all seven letters, choose the one with seven letters over the one with fewer tiles.
- If the there are multiple words that are the same score and same length, pick the first one in supplied list.
Expand Down
2 changes: 1 addition & 1 deletion feedback.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Git hygiene |
Comprehension questions |
**General** |
`score` calculates score, has appropriate params and return value |
`highestScoreFrom` calculates highest scoring word, has appropriate params and return value |
`highestScoringWord` calculates highest scoring word, has appropriate params and return value |
**`Player` object** |
Has `name` and `plays` properties |
Has `play`, `totalScore`, `hasWon` functions |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "ISC",
"dependencies": {
"fs": "0.0.1-security",
"npm": "^5.8.0"
"npm": "^5.10.0"
},
"scripts": {
"test": "jest"
Expand Down
137 changes: 130 additions & 7 deletions scrabble.js
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) {

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.

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;
Loading