Search⌘ K
AI Features

Lesson + Exercises

Explore how to create and combine modular functions using function composition in RamdaJS. Learn to build reusable transformations like uppercasing and reversing names, then apply these patterns to collections of user data.

Function Composition

Compose means to create by combining things.

A Toyota’s roughly 30,000 parts. Composing those useless parts gives you a useful method of transportation.

Same thing with software. Our functions are useless until we compose them with other functions.

Uppercase and Reverse

Here’s our user, bobo.

const bobo = {
  firstName: 'Bobo',
  lastName: 'Flakes'
};

Let’s uppercase and reverse bobo's first name. What functions must you create and compose?

Your end result should be a function upperAndReverseFirstName that takes bobo and returns the correct output.

Javascript (babel-node)
const bobo = {
firstName: 'Bobo',
lastName: 'Flakes'
};
const result = upperAndReverseFirstName(bobo);
console.log({ result });
Javascript (babel-node)
const upperAndReverseFirstName = (user) => {
// your code here
};

Upper and Reverse for All!

After that, how can you make upperAndReverseFirstName work for Bobo and his friends?

const users = [{
  firstName: 'Bobo',
  lastName: 'Flakes'
}, {
  firstName: 'Lawrence',
  lastName: 'Shilling'
}, {
  firstName: 'Anon',
  lastName: 'User'
}];

// ['OBOB', 'ECNERWAL', 'NONA']
Javascript (babel-node)
// paste your previous solution here
const upperAndReverseFirstNames = (users) => {
// new code here
}