-
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?
Conversation
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 |
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.
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 |
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 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
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 |
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 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
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 |
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.
No description provided.