forked from learn-co-curriculum/phase-1-context-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request learn-co-curriculum#1 from learn-co-curriculum/wip-rd
Wip rd
- Loading branch information
Showing
7 changed files
with
415 additions
and
21 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -19,3 +19,4 @@ jspm_packages | |
!/log/.keep | ||
/tmp | ||
|
||
.vscode |
This file contains 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,16 +1,71 @@ | ||
# Title | ||
# JavaScript Advanced Functions: Context Lab | ||
|
||
## Learning Goals | ||
|
||
-SWBAT 1 | ||
-SWBAT 2 | ||
* Explicitly override context with `call` and `apply` | ||
|
||
## Introduction | ||
|
||
## SWBAT 1 | ||
In this lab, we're going to build the time-card and payroll application using | ||
the record-oriented approach again. This lab will feature the same topic and | ||
area of work as the previous lab; _however_, _how_ we call and use functions | ||
will change with our new knowledge. While the code will stay _mostly_ the same, | ||
you're going to need to use `this` a lot more. | ||
|
||
## SWBAT 2 | ||
The tests guide you to implementing a time card system: when someone enters the | ||
company's state of the art technical office, the employee has to insert their | ||
card in a time-clock which will record the time they came in. When it's time to | ||
leave, the employee will "punch out." | ||
|
||
For simplicity's sake, we'll make these assumptions: | ||
|
||
1. Assume that employees always check in and check out | ||
2. Assume employees always check in and our on the hour | ||
3. The time is represented on a 24-hour clock (1300 is 1:00 pm); this keeps the | ||
math easier and is the standard in most of the world | ||
4. When timestamps are needed, they will be provided as Strings in the form: | ||
"YYYY-MM-DD 800" or "YYYY-MM-DD 1800" e.g. "2018-01-01 2300" | ||
5. Employees will never work across days i.e. in at 2200 and out at 0400 the | ||
next day. | ||
|
||
The lab tests will guide you toward a solution. Keep in mind, the goal is to | ||
understand how to "grow" an application in "record-oriented" fashion in | ||
JavaScript, as well as pass the lab. Make sure you're learning about this app | ||
design while you pass the solutions. | ||
|
||
As before, if you find yourself having extra time, use the guidance in the | ||
previous lab to make your application more robust. | ||
|
||
Take advantage of your collection-processing strengths that you trained up over | ||
the last few lessons. | ||
|
||
Put your code in `index.js`. | ||
|
||
## A Mystery on the Horizon | ||
|
||
You'll notice that in this lab we give you the implementation of `allWagesFor`. | ||
As part of writing this challenge, we ran right smack into one of the most | ||
famous bugs in JavaScript land: "the lost context bug." Because we've not | ||
taught you to deal with it, we've "given" you this function. We think you can | ||
solve the other tests with this little piece having been given to you. | ||
|
||
If you find yourself having extra time, try researching this topic on your own. | ||
We'll tell you all about it in our next lesson, though. | ||
|
||
## Conclusion | ||
|
||
This is one of the hardest topics in JavaScript. But you have hands-on | ||
experience with the why and motivations of it! You're so much better off than | ||
most JavaScript hackers who _never_ quite get the hang of it. It's been a lot | ||
of growth, but this hard-won knowledge is going to help you do staggeringly | ||
cool things | ||
|
||
## Resources | ||
|
||
* [`bind`][bind] | ||
* [`call`][call] | ||
* [`apply`][apply] | ||
|
||
[bind]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind | ||
[call]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/call | ||
[apply]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/apply |
This file contains 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,5 +1,22 @@ | ||
const testVar = {} | ||
/* Your Code Here */ | ||
|
||
function testFunc() { | ||
return "hi" | ||
} | ||
/* | ||
We're giving you this function. Take a look at it, you might see some usage | ||
that's new and different. That's because we're avoiding a well-known, but | ||
sneaky bug that we'll cover in the next few lessons! | ||
As a result, the lessons for this function will pass *and* it will be available | ||
for you to use if you need it! | ||
*/ | ||
|
||
let allWagesFor = function () { | ||
let eligibleDates = this.timeInEvents.map(function (e) { | ||
return e.date | ||
}) | ||
|
||
let payable = eligibleDates.reduce(function (memo, d) { | ||
return memo + wagesEarnedOnDate.call(this, d) | ||
}.bind(this), 0) // <== Hm, why did we need to add bind() there? We'll discuss soon! | ||
|
||
return payable | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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
Oops, something went wrong.