This course has been updated! We now recommend you take the Functional-Light JavaScript, v3 course.

Check out a free preview of the full Functional-Lite JavaScript course:
The "Exercise 1" Lesson is part of the full, Functional-Lite JavaScript course featured in this preview video. Here's what you'd learn in this lesson:

In this exercise, you will create a pure function named “bar” to wrap around the function “foo”.

Get Unlimited Access Now

Transcript from the "Exercise 1" Lesson

[00:00:00]
>> [MUSIC]

[00:00:03]
>> Kyle: So we do have an exercise. Exercise 1 helped to try and drill that in to you a little bit. If you're not terribly comfortable with that notion of wrapping something around it, you'll notice that exercise 1 is gonna say exactly what I just suggested, and it's going to be very similar to that.

[00:00:19] So, let's pull up the README. I'll just orient you to exercise 1 very quickly.
>> Kyle: ex1, we're gonna pull up the README and I'll go ahead and pull up the ex1.js as well. So the README is gonna say, make a pure function bar that wraps around the implied impure function foo.

[00:00:43] 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'd just showed you in the slides. It is an impure function. It is making changes to a y and z variable on the outside. And each time I call foo with a different value, I'm getting an actual different end result.

[00:01:03] And if I called foo with 20 each time, I would still get different results. I wouldn't get the same results every time with foo 20. So 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 or wrapper that turns this program into a pure program.

[00:01:24] 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.

[00:01:40] But if you get stuck, the fixed version of all these files is always available to you in that same folder. So, if you get stuck or if you just wanna cheat, you can look at the fixed version of ex1.