-
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?
Conversation
reneemeyer
left a comment
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.
Eric, good start, but you need to work out some of the kinks in these functions. Remember, the purpose of functions in JS is re-usability and the ability to return data. We don't want to hard code any data into a function.
| 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 comment
The 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 comment
The 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.
| //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++) { | ||
| callback(); |
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.
Each item needs to be passed into the callback.
|
|
||
| const assert = require('assert'); | ||
|
|
||
| function forEach(arr, callback) { |
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
| 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
what is the purpose of this internal function?
| //print out the new array | ||
| const doThis = (arr, callBackFunction) => { | ||
| const newArr = []; | ||
| test.forEach((i) => { |
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.
your forEach should loop around the array passed, not a hardcoded array.
| test.forEach((i) => { | ||
| newArr.push(callBackFunction(i)); | ||
| }); | ||
| console.log(newArr); |
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.
you should return the newArr, not console log it
| //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 comment
The 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.
Checkpoint Rubric
This is the rubric that your instructor will use to grade your checkpoints. Please do not edit.
Checkpoint 1
Checkpoint 2
Checkpoint 3