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

first changes to homework #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

OcielC
Copy link

@OcielC OcielC commented Sep 24, 2019

No description provided.

Comment on lines 30 to 46
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
Copy link

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

Comment on lines 102 to 119
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
Copy link

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

Comment on lines 160 to 179
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
Copy link

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

Comment on lines 214 to 223
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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OcielC Good work here on the solution. I see you are using recursion here in this solution, nice way to solve the problem.

Take a look at this solution here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants