-
Notifications
You must be signed in to change notification settings - Fork 0
Class9 higherorder #10
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
base: gh-pages
Are you sure you want to change the base?
Changes from all commits
9b06645
01da042
7d6c868
26d8d99
3cba5e4
5375956
b3a48dd
56f57e6
19f4399
7c87999
d13546e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| `use strict` | ||
|
|
||
| //returns current date and time | ||
| //create a function that inputs the year, month, and day | ||
| //make new var to store the today var and toDateString method | ||
| //use var today with toDateString method | ||
|
|
||
| function dateDisplay(year, month, date) { | ||
| var today = new Date(year, month, date); | ||
| return today.toDateString(); | ||
| } | ||
|
|
||
| dateDisplay(1985, 10, 1); | ||
|
|
||
| //create a function with one argument. | ||
| //the argument should be a number | ||
| //return the argument with the toString() method to make the number a string | ||
|
|
||
| function toNumber(number) { | ||
| return number.toString() | ||
| } | ||
|
|
||
| toNumber(13); | ||
|
|
||
| //create a fucntion that receives one argument | ||
| //argument should be a string | ||
| //use parseInt() method on argument to pull a number out | ||
|
|
||
| function stringNum(str){ | ||
| return parseInt(str); | ||
| } | ||
|
|
||
| stringNum('15 years'); | ||
|
|
||
| //create a function with one argument | ||
| //use the typeOf method on the argument and return the result | ||
|
|
||
| function dataType(dT){ | ||
| return typeof(dT); | ||
| } | ||
|
|
||
| dataType(`words words words`); | ||
|
|
||
| //Create a function with two arguments | ||
| //Inside the function, add the two var together | ||
| //Use parseInt() to take the number out of the string | ||
|
|
||
| function add(numOne, numTwo) { | ||
| return parseInt(numOne) + parseInt(numTwo) | ||
| } | ||
|
|
||
| add(`13`, `17`); | ||
|
|
||
| //write a function that returns a true if two var are truthy | ||
| //if both var are true, show "nope" | ||
| //if both var are false, also show "nope" | ||
| // if one is false and one is true, show "yep!" | ||
|
|
||
| function truest(thingOne, thingTwo) { | ||
| if ((thingOne === true && thingTwo === true) || (thingOne === false && thingTwo === false)){ | ||
| return `nope`; | ||
| } else { | ||
| return 'yep!'; | ||
| } | ||
| } | ||
|
|
||
| truest(true, false); | ||
|
|
||
| //write a function with two arguments | ||
| //if both arguments are false, show a confirmation message | ||
| //if either argument is true, return a negative response | ||
|
|
||
| function womp(dumb, dumber) { | ||
| if (dumb === false && dumber === false) { | ||
| return `yes, they're both false` | ||
| } else { | ||
| return 'nah, try again' | ||
| } | ||
| }; | ||
|
|
||
| womp(false, true); |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const readline = require('readline'); | ||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
|
|
||
|
|
||
| function rockPaperScissors(hand1, hand2) { | ||
| // check for a tie, if it is a tie, return tie, if not check for win | ||
| // rock beats scissors, scissors beats paper, paper beats rock | ||
| //to find who won, compare hand1 to hand2 | ||
| const handOne = 'Hand one wins!' | ||
| const handTwo = 'Hand two wins!' | ||
|
|
||
| if(hand1 === hand2) { | ||
| return "It's a tie!"; | ||
| } else if (hand1 === 'rock'){ | ||
| return hand2 === 'paper' ? handTwo : handOne; | ||
| } else if (hand1 === 'paper') { | ||
| return hand2 === 'scissors' ? handTwo : handOne; | ||
| } else if (hand1 === 'scissors') { | ||
| return hand2 === 'rock' ? handTwo : handOne; | ||
| } | ||
| }; | ||
|
|
||
| function getPrompt() { | ||
| rl.question('hand1: ', (answer1) => { | ||
| rl.question('hand2: ', (answer2) => { | ||
| console.log( rockPaperScissors(answer1, answer2) ); | ||
| getPrompt(); | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| // Tests | ||
|
|
||
| if (typeof describe === 'function') { | ||
|
|
||
| describe('#rockPaperScissors()', () => { | ||
| it('should detect a tie', () => { | ||
| assert.equal(rockPaperScissors('rock', 'rock'), "It's a tie!"); | ||
| assert.equal(rockPaperScissors('paper', 'paper'), "It's a tie!"); | ||
| assert.equal(rockPaperScissors('scissors', 'scissors'), "It's a tie!"); | ||
| }); | ||
| it('should detect which hand won', () => { | ||
| assert.equal(rockPaperScissors('rock', 'paper'), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('paper', 'scissors'), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('scissors', 'rock'), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('scissors', 'paper'), "Hand one wins!"); | ||
| assert.equal(rockPaperScissors('rock', 'scissors'), "Hand one wins!"); | ||
| assert.equal(rockPaperScissors('paper', 'rock'), "Hand one wins!"); | ||
| }); | ||
| it('should scrub input to ensure lowercase with "trim"ed whitepace', () => { | ||
| assert.equal(rockPaperScissors('rOcK', ' paper '), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('Paper', 'SCISSORS'), "Hand two wins!"); | ||
| assert.equal(rockPaperScissors('rock ', 'sCiSsOrs'), "Hand one wins!"); | ||
| });w | ||
| // it('should detect ') | ||
| }); | ||
| } else { | ||
|
|
||
| getPrompt(); | ||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| 'use strict' | ||
|
|
||
| const names = ['athens', 'berlin', 'atlanta', 'seoul', 'los angeles'] | ||
|
|
||
| const printListOfOlympics=(arr)=>{ | ||
| arr.forEach(i => console.log(i)) | ||
| } | ||
|
|
||
| printListOfOlympics(names); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,15 +3,45 @@ | |
| const assert = require('assert'); | ||
|
|
||
| function forEach(arr, callback) { | ||
| // Your code here | ||
| // create an array with whatever you want in it | ||
| const arrProblemOne = [1, 2, 3] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is unnecessary. |
||
|
|
||
| //make a for loop that runs the number of items in the array amount of times. | ||
| //make a variable that prints a phrase the amount of times defined by the for loop | ||
| for (let i = 0; i < arrProblemOne.length; i++) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Your for loop should loop around the arr that the user passes in, not a hard coded array. |
||
| callback(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Each item needs to be passed into the callback. |
||
| } | ||
| } | ||
| } | ||
|
|
||
| function map(arr, callback) { | ||
| // Your code here | ||
| // Create an array, put whatever you want in it | ||
| const test = ['1', '2', '3', '4', '5', '6']; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is unnecessary |
||
|
|
||
| //doThis(), a function that creates a new array, then does whatever function you want when you call doThis to the original array | ||
| //pushes the result of the called function to the new array | ||
| //print out the new array | ||
| const doThis = (arr, callBackFunction) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the purpose of this internal function? |
||
| const newArr = []; | ||
| test.forEach((i) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. your forEach should loop around the array passed, not a hardcoded array. |
||
| newArr.push(callBackFunction(i)); | ||
| }); | ||
| console.log(newArr); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should return the newArr, not console log it |
||
| }; | ||
| } | ||
|
|
||
| function filter(arr, callback) { | ||
| // Your code here | ||
| //create an array with three numbers | ||
| const arrProblemThree = [1, 2, 3]; | ||
|
|
||
| //longestWords(), create a function that takes an array and a function | ||
| //the called function affects the called array | ||
| //a new, empty array accepts the results of the function | ||
| const filtered = (arrTwo, callbackTwo) => { | ||
| const arrResultThree = []; | ||
| if (callbackTwo(arrTwo[i])) arrResultThree.push(arrTwo[i]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where is i defined? This doesn't make any sense. Also where did longestWords come from? Please follow the exact directions. This function should take an array and a function as arguments. It should return an array with only the items that return true in the function. Don't use hard coded arrays or functions. |
||
| } | ||
| console.log(arrResultThree); | ||
| } | ||
|
|
||
| function some(arr, callback) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,6 @@ | |
| <title></title> | ||
| </head> | ||
| <body> | ||
| <h1>Hello World!</h1> | ||
| <h1>Hello Eric, how are you!</h1> | ||
| </body> | ||
| </html> | ||
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.
es6 syntax