Functional-Light JavaScript, v3

Data Structure Operations

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 "Data Structure Operations" 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 emphasizes the importance of being able to generalize functional methods to use across any collection or data structure, such as objects and binary trees.

Preview
Close

Transcript from the "Data Structure Operations" Lesson

[00:00:00]
>> Kyle Simpson: At the beginning of this unit, I mentioned that we were gonna use arrays, lists as a way to illustrate a lot of these concepts. And we have, we've used a lot of arrays. We've done a bunch of that in the exercise. But we really want to generalize everything that we've been talking about to the idea of any collection to any data structure.

[00:00:17]
So we're gonna now take those same ideas of map, filter, and reduce, and, in fact, indeed even something like a transducing. We wanna take map, filter, and reduce. And we wanna think about them at the bigger level, which would be at the data structure level or at the more general level.

[00:00:32]
So if I had an object, like obj here at the top, and I wanted to map over that object and do something, in this case, make all of the values lowercase. Then I can define a map object function, which is similar to the map that we know that works with arrays, but this one works with objects.

[00:00:51]
And this one loops over all of the keys in an object. And it calls some mapper function. In this case, that mapper function makes everything to lowercase. So thinking about mapping as an operation where we are essentially lifting a value or adapt. I'm sorry, lifting an operation or adapting an operation across all of the values in a container, right?

[00:01:17]
So it could be an array. It could be an object like here, where we're just doing the keys. It could be a binary tree. You can imagine doing a map across all of the leaf nodes in a binary tree, for example. So any sort of data structure, as long as we can create a mapper for it, we can adapt that operation to work across the entire set of those values.

[00:01:40]
So imagine in your mind, what would filter and reduce look like in an object sense?

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