Functional JavaScript First Steps

# Function Composition Exercise

## Anjana Vakil

Software Engineer & Educator

### Check out a free preview of the full Functional JavaScript First Steps course

The "Function Composition Exercise" Lesson is part of the full, Functional JavaScript First Steps course featured in this preview video. Here's what you'd learn in this lesson:

Students are instructed to write a pipeline function that receives a series of functions as input and then use the pipeline technique to convert strings from snake_case to camelCase.

Preview
Close

### Transcript from the "Function Composition Exercise" Lesson

[00:00:00]
>> So this is what we're gonna do in our next exercise, which is exercise function composition. Once again, you can find it by going to that collection page. You'll find it in there. And you can take a look at the instructions to understand what you're being asked to do.

[00:00:20]
But let me run it through run us through it really quickly. Pipelining is this type of thing that we were talking about where we take the inputs from one function, pass them into the next function. Excuse me, we take the inputs from one function, the outputs from that get passed into the next function, the outputs from that get passed into the next function.

[00:00:42]
And we create kind of a pipeline, through which the data flows. So what we're gonna do is write a pipeline function, which is gonna make it really easy for us to do that simply by passing in. A series of functions to a pipeline function. We get to compose them all together into a single function, which is going to flow the data through.

[00:01:06]
So your first task is to implement that. And there are some tests below, where you'll wanna look for those little funky faces to turn into TAs again, to let you know that your pipeline is working. And the way we'll be using it, is by calling it on a series of single argument functions like this, so, that we no longer have to worry about that nested call signature.

[00:01:28]
It just makes it a little bit easier to read, and to understand what order these functions are gonna be applied in. And then, if you really wanna challenge you can try to implement pipeline with the reduce function from earlier. The second part of this exercise is that we're going to try to transform some data.

[00:01:53]
Using these functional pipelines, so what we're going to do is take strings in a certain case, like snake case, which you might be familiar with. If you've worked in Python. This is kind of a convention for a variable naming in Python and turn them into more JavaScript IE camel case strings like to sort of translate our pythonic variables, to JavaScript variables or what have you.

[00:02:19]
And so what you're going to do is try to write a series of small single arguments, single operation, single action sort of functions, that are going to do just one transformation at a time. Then we're going to compose them together into a program a function that's going to take in a snake case string and return a camel case string.

[00:02:42]
And then there are a few more challenge exercises for you as well to do variations on this on this snake to camel pipeline.

### Learn Straight from the Experts Who Shape the Modern Web

• In-depth Courses