Solution Review: List of Cubes

Let’s go over the solution for the challenge: List of Cubes.

We'll cover the following

Task

In this challenge, you were provided a list of integers and you had to create a new list of integers which was composed by the cubes of the original list.

Solution

You were given a list, integers. To transform each item of integers into its cube form, you had to use the map() method.

var cubes = integers.map()

The cube of an integer is simply that integer multiplied by itself three times.

(integer) => integer * integer * integer

Finally, the requirement was that the output be a list. For this, you can use the toList() method.

.toList()

Combining all three elements:

var cubes = integers.map((integer) => integer * integer * integer).toList(); 

You can find the complete solution below:

You were required to write the code given on line 3.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy