forked from bloominstituteoftechnology/JavaScript-II
-
Notifications
You must be signed in to change notification settings - Fork 0
itel-domingo #1
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
Merged
Merged
itel-domingo #1
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
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 |
|---|---|---|
|
|
@@ -3,44 +3,59 @@ | |
| const items = ['Pencil', 'Notebook', 'yo-yo', 'Gum']; | ||
|
|
||
| /* | ||
|
|
||
| //Given this problem: | ||
|
|
||
| function firstItem(arr, cb) { | ||
| // firstItem passes the first item of the given array to the callback function. | ||
| } | ||
|
|
||
| // Potential Solution: | ||
| function firstItem(arr, cb) { | ||
| return cb(arr[0]); | ||
| } | ||
|
|
||
| firstItem(items, function(first) { | ||
| console.log(first) | ||
| }); | ||
|
|
||
| */ | ||
|
|
||
|
|
||
| function getLength(arr, cb) { | ||
| // getLength passes the length of the array into the callback. | ||
| return cb(arr.length); | ||
| } | ||
| getLength(items, length => console.log(length)); | ||
|
Collaborator
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. look good |
||
| //////// end of code ///////// | ||
|
|
||
|
|
||
| function last(arr, cb) { | ||
| // last passes the last item of the array into the callback. | ||
| return cb(arr[arr.length - 1]); | ||
| } | ||
| last(items, last => console.log(last)); | ||
| //////// end of code ///////// | ||
|
|
||
|
|
||
| function sumNums(x, y, cb) { | ||
| // sumNums adds two numbers (x, y) and passes the result to the callback. | ||
| return cb(x + y); | ||
| } | ||
| //////// end of code ///////// | ||
|
|
||
|
|
||
| function multiplyNums(x, y, cb) { | ||
| // multiplyNums multiplies two numbers and passes the result to the callback. | ||
| return cb(x * y); | ||
| } | ||
| //////// end of code ///////// | ||
|
|
||
|
|
||
| function contains(item, list, cb) { | ||
| // contains checks if an item is present inside of the given array/list. | ||
| // Pass true to the callback if it is, otherwise pass false. | ||
| if (list.item === true) { | ||
| return cb(true); | ||
| } else { | ||
| return cb(false); | ||
| } | ||
| } | ||
|
|
||
| /* STRETCH PROBLEM */ | ||
|
|
@@ -49,4 +64,4 @@ function removeDuplicates(array, cb) { | |
| // removeDuplicates removes all duplicate values from the given array. | ||
| // Pass the duplicate free array to the callback function. | ||
| // Do not mutate the original array. | ||
| } | ||
| } | ||
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 |
|---|---|---|
| @@ -1,11 +1,33 @@ | ||
| // ==== Challenge 1: Write your own closure ==== | ||
| // Write a simple closure of your own creation. Keep it simple! | ||
|
|
||
| const counter = () => { | ||
|
Collaborator
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. the counter are look good |
||
| function mySuccess(myClass, timeline) { | ||
| const className = myClass; | ||
| function text() { | ||
| const time_line = timeline; | ||
| console.log(`Hello, ${className} I'm back to the ${time_line}`); | ||
| } | ||
| text(); | ||
| // Return a function that when invoked increments and returns a counter variable. | ||
| } | ||
| mySuccess("WEBFT 17", 'future'); | ||
|
|
||
| // ==== Challenge 2: Create a counter function ==== | ||
| const counter = () => { | ||
| let num = 0; | ||
| function increase() { | ||
| num++; | ||
| return num; | ||
| } | ||
| return increase; | ||
| } | ||
| let newCount = counter(); | ||
| console.log(newCount()); | ||
|
|
||
| // Return a function that when invoked increments and returns a counter variable. | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| // Example usage: const newCounter = counter(); | ||
| // newCounter(); // 1 | ||
| // newCounter(); // 2 | ||
|
|
||
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.
the test are look good