In this exercise, you must create a pure function named “bar” to wrap around the function “foo."
(Eastern wind music) - So we do have an exercise. Exercise one. Help to try to drill that into you a little bit if you're not terribly comfortable with that notion of wrapping something around it. You'll notice exercise one is going to say exactly what I just suggested. It's going to be very similar to that. So, let's pull up the readme. I'll just orient you to exercise one very quickly. Ex.1. We're going to pull up the readme and I'll go ahead and pull up the ex1.js as well.
So the readme is going to say make a pure function bar that wraps around the implied impure function foo. Let me zoom out just a little bit so we can see. There I have a foo that's doing something very similar to what I just showed you in the slides. It is an impure function. It is making changes to a Y and a Z variable on the outside. And each time I call foo with a different value, I'm getting an actual different end result. And if I called foo with 20 each time, I would still get different results.
I wouldn't get the same result every time with foo 20. Your task, very quickly, is to define a bar, a wrapper, very much like the last slide that I just showed you. Define a bar, a wrapper that turns this program into a pure program. Encapsulates all of that state. I'll give you three to five minutes. We'll take a break for just a few minutes while you work on that. And then I'll walk you through the exercise. Just as a reminder, as with all my exercises, you'll notice that if you get stuck obviously you can ask questions.
But if you get stuck the fixed versions of all these files is always available to you in that same folder. So if you get stuck or if you just want to cheat you can look at the fixed version in ex.1.
This course was created by Frontend Masters. It was originally released on 03/08/2016. We're pleased to host this training in our library.
- Pure functions
- Manual composition
- Composition utility
- List operations