-
Notifications
You must be signed in to change notification settings - Fork 12
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
first changes to homework #4
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,19 @@ Use the following test cases to confirm your program meets the success criteria | |
console.log('Problem 1:') | ||
|
||
// Add your code below this line | ||
|
||
function blackJack(playerCardScore, dealerCardScore) { | ||
if (playerCardScore <= 21 && dealerCardScore <= 21) { | ||
return Math.max(playerCardScore, dealerCardScore) | ||
} else if (playerCardScore <= 21) { | ||
return playerCardScore | ||
} else if (dealerCardScore <= 21) { | ||
return dealerCardScore | ||
} else { | ||
return 0 | ||
} | ||
} | ||
|
||
console.log(blackJack(19, 21)) | ||
// Add your code above this line | ||
|
||
/** added for formatting purposes **/ | ||
|
@@ -90,7 +102,20 @@ Use the following test cases to confirm your program meets the success criteria | |
console.log('Problem 2:') | ||
|
||
// Add your code below this line | ||
function wordCount(phrase) { | ||
const wordPhrase = phrase.replace(/[,]/g, '') | ||
const wordCountObject = {} | ||
|
||
wordPhrase.split(' ').forEach(function (currentValue) { | ||
wordCountObject[currentValue] = wordCountObject[currentValue] ? ++wordCountObject[currentValue] : 1 | ||
}) | ||
|
||
return wordCountObject | ||
} | ||
|
||
const result = wordCount("Humpty Dumpty sat on a wall Humpty Dumpty had a great fall") | ||
|
||
console.log(result) | ||
// Add your code above this line | ||
Comment on lines
102
to
119
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. @OcielC Good job here putting together this solution. Good use of chaining the split and forEach methods and using the conditional ternary operator to either add the new word to the object with the value of 1 or find the word in the object if it exists and increment the value by 1. Take a look at an alternate solution here |
||
|
||
/** added for formatting purposes **/ | ||
|
@@ -135,7 +160,22 @@ Use the following test cases to confirm your program meets the success criteria | |
console.log('Problem 3:') | ||
|
||
// Add your code below this line | ||
|
||
function scrabbleScore(word) { | ||
const letters = word.split(' ') | ||
const wordCount = {} | ||
|
||
letters.forEach((letter) => { | ||
if (wordCount[letter] === undefined) { | ||
wordCount[letter] = 1 | ||
} else { | ||
wordCount[letter] += 1 | ||
} | ||
// console.log(wordCount) | ||
}) | ||
return wordCount | ||
} | ||
|
||
console.log(scrabbleScore('cabbage')) | ||
// Add your code above this line | ||
Comment on lines
160
to
179
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. @OcielC Good work coming up with this solution here. for this assignment, it needed to be done slightly different. This solution would work well for problem 3 and this problem here you had to compare each letter of the string with a letter that will give you a certain amount of points per letter. Take a look at this solution here |
||
|
||
/** added for formatting purposes **/ | ||
|
@@ -174,7 +214,12 @@ Use the following test cases to confirm your program meets the success criteria | |
console.log('Problem 4:') | ||
|
||
// Add your code below this line | ||
function isPalindrome(word, i = 0) { | ||
const j = word.length - 1 - i; | ||
return i >= j ? true : word[i] === word[j] && isPalindrome(word, i + 1); | ||
} | ||
|
||
console.log(isPalindrome('run')) | ||
// Add your code above this line | ||
Comment on lines
214
to
223
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. |
||
|
||
/** added for formatting purposes **/ | ||
|
@@ -212,4 +257,4 @@ console.log('Problem 5:') | |
|
||
/** added for formatting purposes **/ | ||
console.log('') | ||
console.log('-----------------') | ||
console.log('-----------------') |
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.
@OcielC Good Job here on this solution. Using the conditionals to check for the outcomes for the game and utilizing the Math.max method was a good choice for this use case.
Take a look at this solution here