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
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
51 changes: 48 additions & 3 deletions pset-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines 30 to 46
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


/** added for formatting purposes **/
Expand Down Expand Up @@ -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
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


/** added for formatting purposes **/
Expand Down Expand Up @@ -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
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


/** added for formatting purposes **/
Expand Down Expand Up @@ -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
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


/** added for formatting purposes **/
Expand Down Expand Up @@ -212,4 +257,4 @@ console.log('Problem 5:')

/** added for formatting purposes **/
console.log('')
console.log('-----------------')
console.log('-----------------')