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

completed hw #10

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

completed hw #10

wants to merge 1 commit into from

Conversation

sad3xoxo
Copy link

yay

Comment on lines +321 to +344
function doubleLetters (word) {
const wordLetters = word.split('')
let hasDoubleLetters = false

// iterate through letters of the submitted word
wordLetters.forEach((letter, index) => {
// declare the current letter and previous letter of the iteration
const currentLetter = wordLetters[index]
const previousLetter = wordLetters[index - 1]

// debug
// console.log(`current letter is ${currentLetter}. previous letter was ${previousLetter}.`)

// if they're the same, then double letters are present,
// return true
if (currentLetter === previousLetter) {
hasDoubleLetters = true
}
})

return (hasDoubleLetters)
}

console.log(doubleLetters('apple'))
Copy link

Choose a reason for hiding this comment

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

@sad3xoxo Great job, the solution here looping through the elements and comparing current and previous to determine if the use case has a repeating letter.
take a look at an alternative approach here

Comment on lines +271 to +287
function isPalindrome (word) {
if (word === reverseWord(word)) {
return true
} else {
return false
}
}

function reverseWord (fwd) {
const str = fwd.split('')
const reverseStr = str.reverse()
const reversedWord = reverseStr.join('')

return reversedWord
}

console.log(isPalindrome('run'))
Copy link

@Tech-J Tech-J Oct 8, 2019

Choose a reason for hiding this comment

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

@sad3xoxo Nice work, Good job creating the function to check to see if the value is palindrome and good job creating the function reverseWord to handle returning the reversed string.
Take a look at this solution here

Comment on lines +186 to +232
const pointChart = [
{ letters: 'aeioulnrst', points: 1 },
{ letters: 'dg', points: 2 },
{ letters: 'bcmp', points: 3 },
{ letters: 'fhvwy', points: 4 },
{ letters: 'k', points: 5 },
{ letters: 'jx', points: 8 },
{ letters: 'qz', points: 10 }
]

function scrabbleScore (word) {
const lettersInWord = word.split('')
let wordScore = 0

// iterate over the letters in the submitted word
lettersInWord.forEach(function (letter) {
// interate over the points array and find which letter
// is currently selected
pointChart.forEach((value) => {
// debug
// console.log(value['letters'])

// create an array of letters that align the current
// amount of points to be given. these letters will be compared
// against the current letter in the word that was submitted
const comparisonLetters = value.letters.split('')

// debug
// console.log(comparisonLetters)

// find if the current letter from the submitted word exists
// within the set of letters for this point value.
// if it does, add points. if not, the set the loop proceeds
// to the next set of letters associated with value['points']
if (comparisonLetters.find(element => element === letter)) {
wordScore += (value.points)

// debug
// console.log(`new wordScore is ${wordScore}`)
}
})
})

return (`This word is worth ${wordScore} points`)
}

console.log(scrabbleScore('function'))
Copy link

Choose a reason for hiding this comment

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

@sad3xoxo Good Job here with this solution. I see you grouped the letters and values in an array of objects. This is a good way to structure your data for an example like this.
Take a look at this approach here

Comment on lines +121 to 141
function wordCount (phrase) {
const words = phrase.split(' ')
// empty array for counting words
const wordCounter = {}

// for each word in the phrase
words.forEach((word) => {
if (wordCounter[word] === undefined) {
// debug
// console.log ('word doesnt exist. adding word')
wordCounter[word] = 1
} else {
wordCounter[word] = wordCounter[word] + 1
}
})

return wordCounter
}

console.log(wordCount('Humpty Dumpty sat on a wall Humpty Dumpty had a great fall'))
// 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.

@sad3xoxo Great Job on this solution utilizing the string method split() to create an array with each word and loop through each element to check if the word exists and to increment the value if the word does exist.
Take a look at this approach here

@Tech-J Tech-J added the Approved label Oct 8, 2019
Comment on lines +33 to +60
function blackJack (playerCardScore, dealerCardScore) {
// first, let's determine if there are any entries above 21
if ((playerCardScore > 21) && (dealerCardScore > 21)) {
return 0
} else if (playerCardScore > 21) {
return dealerCardScore
} else if (dealerCardScore > 21) {
return playerCardScore
} else {
// if none of the entries are above 21 the score will be calculated
calculateScore(playerCardScore, dealerCardScore)
}
}

function calculateScore (player, dealer) {
// calculate the difference from 21 for each score
const playerScore = 21 - player
const dealerScore = 21 - dealer

// if playerScore has a larger difference from 21 then return dealerScore
if (playerScore > dealerScore) {
return dealerScore
} else {
return playerScore
}
}

console.log(blackJack(19, 22))
Copy link

Choose a reason for hiding this comment

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

@sad3xoxo Good work here on this problem I see you have your blackjack function checking to see the player's values and you have the calculate score to return the score.
For calculateScore(playerCardScore, dealerCardScore) since that function is returning a value you need to include the keyword return. the return will allow you to get the value from the calculateScore function and display is you when you console.log(blackJack(19, 22)) on line 60.
One suggestion for your calculateScore function currently you're returning the playerScore/dealerScore after you have subtracted 21 - player/dealer. You could return the player or dealer value in the conditional statement.
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