Conversation
| const onePoint = [ | ||
| 'A', | ||
| 'a', | ||
| 'E', | ||
| 'e', |
There was a problem hiding this comment.
Remove the upper or lower case characters and just one case, then run .toUpperCase or .toLowerCase on the input
| const scrabble = (str) => { | ||
| if (str === null) { | ||
| return 0 | ||
| } |
There was a problem hiding this comment.
const ucStr = str.toUpperCase()
| let tmpStr = '' | ||
|
|
||
| for (let i = 0; i <= str.length - 1; i++) { | ||
| if (!['[', ']'].includes(str[i])) { |
There was a problem hiding this comment.
const doubleLetters = ['[', ']']
if (!doubleLetters.includes(str[i])) {
| tmpStr[0] === '{' && | ||
| tmpStr[2] !== '}' && | ||
| lastChar === '}' && | ||
| charBeforeLast !== '{' |
There was a problem hiding this comment.
Create one or more variables
| let strToCheck = str | ||
| let newStr = '' | ||
|
|
||
| if (doubleWord.valid === true) { |
|
|
||
| for (let i = 0; i < strToCheck.length; i++) { | ||
| if (strToCheck[i] === '{') { | ||
| count1 += 1 |
There was a problem hiding this comment.
A better name for count1 would be useful
| return doubleLettersObj | ||
| } | ||
|
|
||
| const tripleLettersChk = (str) => { |
There was a problem hiding this comment.
validateTripleLetters or checkTripleLetters
| if ( | ||
| str === '' || | ||
| str === null || | ||
| str === ' \t\n' || | ||
| typeof str !== 'string' || | ||
| str === undefined || | ||
| invalidChars || | ||
| !doubleLetters.valid || | ||
| !tripleLetters.valid | ||
| ) { |
There was a problem hiding this comment.
const isEmpty = str === '' || str === null || str === ' \t\n' || str === undefined
const isValid = ...
if (isEmpty || !isValid)| } else if (tenPoints.includes(i)) { | ||
| points += 10 | ||
| } | ||
| calcDoubledLetters.doubleLettersPoints = points * 2 |
There was a problem hiding this comment.
2 is a magic number. Move to a variable that describes it, e.g. doubleMultiplier, tripleMultiplier
| const fourPoints = ['F', 'H', 'V', 'W', 'Y', 'f', 'h', 'v', 'w', 'y'] | ||
| const fivePoints = ['K', 'k'] | ||
| const eightPoints = ['J', 'X', 'j', 'x'] | ||
| const tenPoints = ['Q', 'Z', 'q', 'z'] |
There was a problem hiding this comment.
const points = {
'a': 1,
'b': 3,
...
}
No description provided.