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

Add files via upload #9

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
127 changes: 127 additions & 0 deletions pset-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ console.log('Problem 1:')

// Add your code below this line

function blackJack(playerCardScore, dealerCardScore) {

if (playerCardScore>21 && dealerCardScore>21) {
result = 0
} else if (playerCardScore>21 || dealerCardScore>21) {
result = Math.min(playerCardScore, dealerCardScore)
}
else {
result = Math.max(playerCardScore, dealerCardScore)
}
return result
}

const a=19
const b=21
console.log("Test case a=19 and b=21. Winner is:")
console.log(blackJack(a,b))

Comment on lines +34 to +51
Copy link

Choose a reason for hiding this comment

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

@AtleLohrmann Good job here creating a function and utilizing the conditionals to get to your solution. Nice job utilizing the Math library methods max and min it's a nice feature for this use case.
take a look at this alternate solution here


// Add your code above this line

/** added for formatting purposes **/
Expand Down Expand Up @@ -90,6 +109,28 @@ 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) {
// Have to split the sentence into words
// first get rid of possible commas --
const nocomma=phrase.replace(',',"")
const words=nocomma.split(" ")
const nWord={}
//loop through the number of words in the sentence and
//check for each of the words we have already identifies
words.forEach((word) => {
// console.log(nWord[word])
if (nWord[word] === undefined) {
nWord[word] = 1
} else {
nWord[word]++
}
}) // closing the loop
return nWord
} // closing the function

const phrase="Baby shark, doo doo doo doo doo doo"
console.log("Test:" + phrase)
console.log(wordCount(phrase))
Comment on lines +112 to +133
Copy link

Choose a reason for hiding this comment

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

@AtleLohrmann Nice job her creating this function here to take to create the object with the phrase and value of each time a word is repeated. Good job on the splitting the string and checking each word to either set to one if it doesn't exist else increment the value by 1.
Take a look at this solution here


// Add your code above this line

Expand Down Expand Up @@ -135,6 +176,47 @@ 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) {
// Have to split the sentence into words
let characters=word.split("")
let points=0
// put the cases inside arrays to facilitate adding points
const onePoint=["a","e","i","o","u","l","n","r","s","t"]
const twoPoint=["d","g"]
const threePoint=["b","c","m","p"]
const fourPoint=["f","h","v","w","y"]
const fivePoint=["k"]
const eightPoint=["j","x"]
const tenPoint=["q","z"]
//loop through the number of characters in the workd

for (var i = 0; i < characters.length; i++) {
// check which point categories the character belongs in and add points
if (onePoint.includes(characters[i])) {
points=points+1
} else if (twoPoint.includes(characters[i])) {
points=points+2
} else if (threePoint.includes(characters[i])) {
points=points+3
} else if (fourPoint.includes(characters[i])) {
points=points+4
} else if (fivePoint.includes(characters[i])) {
points=points+5
} else if (eightPoint.includes(characters[i])) {
points=points+8
} else if (tenPoint.includes(characters[i])) {
points=points+10
}//find in the point categories
} //for each charater in the test word
return points
} // end of function

const word="function"
console.log("Test: " + word)
console.log("Number of points: " + scrabbleScore(word))
Comment on lines +179 to +216
Copy link

@Tech-J Tech-J Oct 10, 2019

Choose a reason for hiding this comment

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

@AtleLohrmann Great work here on this problem. good use of the array method includes to check if each character against the point arrays and add the points up.
Take a look at this solution here





// Add your code above this line

Expand Down Expand Up @@ -174,6 +256,31 @@ 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){
// split the word into characters
let wordChar=word.split("")
let reverseWord=[]
//console.log(wordChar)
// add the characters into reverseWord in reverseorder
for (let i = 0; i < wordChar.length; i++) {
reverseWord[wordChar.length-i-1]=wordChar[i]
}
// Output the word and the revers for debugging
console.log("Original word: " + word)
console.log("Revers word: " + reverseWord.join(""))
// check if we have a Palindrome
if (word===reverseWord.join("")) {
return true
}
}

const test="racecar"
if (isPalindrome(test))
{console.log("is a Palindrome")
} else
{console.log("maybe undefined")
}

Comment on lines 256 to +283
Copy link

@Tech-J Tech-J Oct 10, 2019

Choose a reason for hiding this comment

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

@AtleLohrmann Good work on this problem. Good job using that isPalindrome function to compare the word as is and reversed. I see your looping through each character in reverse and adding it to your array reverseWord. where you split the word into the array wordChar, there is a method for arrays called reverse() which would reverse the array for you. It's a good tool and you could check out some information on it here
One suggestion for lines 277 to 281 you could wrap that up in a function and call it.
take a look at this solution here


// Add your code above this line

Expand Down Expand Up @@ -208,6 +315,26 @@ console.log('Problem 5:')

// Add your code below this line

function doubleLetters(word) {
// Have to split the sentence into words
// first get rid of possible commas --
const characters=word.split("")
let double=false
//loop through the number of words in the sentence and
//check for each of the words we have already identifies
for (var i = 0; i < (word.length)-1; i++) {
if (characters[i]===characters[i+1]) {
double=true
}
} //closing the todoloop
return double
} // closing the function

const testword="runu"
console.log("Test: " + testword)
console.log("Result for double character test:", doubleLetters(testword))


Comment on lines +318 to +337
Copy link

Choose a reason for hiding this comment

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

@AtleLohrmann Good work here on this here. Your looping through each letter and comparing it against the next letter, good job coming to that solution. One suggestion since your using the boolean to determine if the consecutive letter exist you could return true on line 327 and return false on line 330. the benefit of that is if the letter repeats itself twice when your return true that stops the program and doesn't continue searching the other letters since you got your answer.
take a look at this solution here

// Add your code above this line

/** added for formatting purposes **/
Expand Down