forked from AustinCodingAcademy/javascript-workbook
-
Notifications
You must be signed in to change notification settings - Fork 0
higherOreder #16
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
Open
GormanGit
wants to merge
2
commits into
gh-pages
Choose a base branch
from
class10-higherOrder
base: gh-pages
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
higherOreder #16
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,18 +2,57 @@ | |
|
|
||
| const assert = require('assert'); | ||
|
|
||
| function forEach(arr, callback) { | ||
| // Your code here | ||
| } | ||
|
|
||
| function map(arr, callback) { | ||
| // Your code here | ||
| } | ||
| // function forEach(arr, callback){ | ||
| // ** method | ||
| // var arr1 = [1, 2, 3,] | ||
| // arr1.forEach(function(entry){ | ||
| // console.log(entry) | ||
| // }) | ||
|
|
||
| function filter(arr, callback) { | ||
| // Your code here | ||
| // this is forEach function that iterates over each item in array with defined function. for each item | ||
| // in array dot length perform inputfunction | ||
| const forEach = (inputArray, inputFunction) => { | ||
| for (let i = 0; i < inputArray.length; i++){ | ||
| inputFunction(inputArray[i]); | ||
|
|
||
| } | ||
| }; | ||
| //this is the array | ||
| const fullArray = [1, 2, 3]; | ||
| // this is a function that uses fullArray as the argument and then console logs it as the function. | ||
| function funky(fullArray) { | ||
| console.log(fullArray); | ||
| } | ||
| //calling fullArray and funky to run the forEach function logs the exact same thing as a forEach method | ||
| forEach(fullArray, funky); | ||
|
|
||
| // function map(arr, callback) { | ||
| // | ||
| // } | ||
| const map = (arg1, arg2) => { | ||
| let nums = []; | ||
| arg1.forEach(index => nums.push(arg2(index))); | ||
| return nums; | ||
| }; | ||
| const add2 = i => i+2; | ||
| const array = [1, 2, 3, 4]; | ||
| map(array, add2); | ||
| // function filter(arr, callback) { | ||
| // // Your code here | ||
| // } | ||
| const filter = (inpt , inFun) => { | ||
| let arr1 = []; | ||
| for (let i = 0; i < inpt.length; i++){ | ||
| if(inFun(inpt[i])) { | ||
| arr1.push(inpt[i]); | ||
| } | ||
| }return arr1; | ||
|
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. Put the return on its own line. |
||
| }; | ||
| const filtArray = [1,2,3,4]; | ||
| filter(filtArray, (x) => { | ||
| return x > 2; | ||
| }); | ||
| function some(arr, callback) { | ||
| // Your code here | ||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 map function works perfectly, but some of the things inside aren't named well.
indexisn't the index, it's the item, and the return array won't always be full of numbers, sonumsdoesn't make sense. But it works!