Functional-Light JavaScript, v3

List Operations Exercise

Kyle Simpson

Kyle Simpson

You Don't Know JS
Functional-Light JavaScript, v3

Check out a free preview of the full Functional-Light JavaScript, v3 course

The "List Operations Exercise" Lesson is part of the full, Functional-Light JavaScript, v3 course featured in this preview video. Here's what you'd learn in this lesson:

Kyle instructs students to practice using list operations by writing three versions of an adding function that take in a list of functions to evaluate.

Preview
Close

Transcript from the "List Operations Exercise" Lesson

[00:00:00]
>> Kyle Simpson: All right, let's try an exercise to practice these list operations, actually, data structure operations, but these list operations map, reduce, and filter. And actually this exercise is going to include some other review of functional programming concepts that we've been learning up to this point in the course.

[00:00:17]
So we're going to get a chance to bring in several different things like closure and recursion and other things. All right, so the set up of this exercise is really important because if you look at the exercise file, it's basically empty. I haven't provided you anything because the instructions are very explicit on what you wanna do.

[00:00:36]
And unlike many times where I know the temptation is to sort of skip to the good parts [LAUGH] of some exercise. It's really important that you follow each of these steps in order because they're taking you through a derivation of problems that you need to bring in different concepts from our course so far to solve.

[00:00:55]
So starting with one, two, three and four those are fairly straightforward. Item five on this list is where you're gonna spend most of your time on this exercise. You're gonna be writing an addn utility that uses functions that you've created in items one through four. But this addn utility you gonna implement it potentially multiple times.

[00:01:17]
At a minimum, you need at least one working implementation. And you can implement it with a looping construct, like a for loop or a while loop. You could implement it a second time using recursion. We talked about that a little bit earlier in the course. You could use recursion to implement this.

[00:01:34]
And still, a third time, and this is really the important one for this particular exercise, you can use a functional helper like reduce. So at a minimum, I want you to implement it at least one time, try your hand at maybe two or three times and definitely at least try it with the reduce.

[00:01:51]
So you'll spend a pretty good significant chunk of time trying to get the addn function to work there. Another little hint, it's not here in the read me, but I just wanna point this out. What you're gonna be doing is dealing with functions all-over, and that shouldn't be surprising, this is a functional programming course.

[00:02:06]
But there's a temptation to want to eagerly reduce everything back to concrete values. And the temptation to eagerly reduce these partial sums back to concrete values is gonna lead you into a much more awkward, and less performing solution here. So think about what we've talked about so far in this course.

[00:02:25]
The idea of deferring work by having things wrapped up in functions. The deferral of work till the end is actually the clue of how to get a much better solution to the addn problem. And that's true regardless of which of the three implementations that you choose, okay? So just keep that in mind, the idea of deferring work, deferring the addn until a later time.

[00:02:46]
Keep everything at the function realm and the solution will end up a lot easier. But that's not the end of the exercise. They're still items six, seven and eight to go through. That's where you're going to, again, get more practice with our list operations like our filter our map and our reduce.

[00:03:05]
Okay, so you should allow a pretty good chunk of time to work on this exercise. It is challenging. It is bringing in not only the concepts from this unit of discussion, but also many of the things that we've covered up unto this point. And so you really want to take your time and make sure you're getting all of those pieces right.

[00:03:21]
Take definitely a good chunk of time to work on this exercise.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now