Wow! This problem is kind of tricky. If you're ready to put your thinking cap on, brace yourself and good luck! Otherwise, you can skip it for now and return any time later.
In this problem, you need to complete the implementation of three functions.
- The
multifunctionalMapperfunction that accepts a list of operators (mappers) and returns a new operator. The new operator just accepts a list of integer numbers and sequentially applies each mapper to each number in the list (performs multiple transformations). It produces a list of transformed values. - Based on
multifunctionalMapper, implement themultTwoAndThenAddOneTransformationoperator that multiplies each integer number by two and then adds one to it. The operator is applied to each number in the input list. - Based on
multifunctionalMapper, implement thesquareAndThenGetNextEvenNumberTransformationoperator that squares each integer number and then calculates the next even number following it. The operator is also applied to each number in the input list.
Here is an example. The identityTransformation is based on the multifunctionalMapper function identity. It doesn't change values in the input list but repeats identity transformation three times, just for the sake of an example.
Let's take a look at two examples of how the operators should work.
Example 1. The input list is [1, 1, 1, 1]
identityTransformationreturns the list[1, 1, 1, 1]multTwoAndThenAddOneTransformationreturns the list[3, 3, 3, 3]squareAndThenGetNextEvenNumberTransformationreturns the list[2, 2, 2, 2]
Example 2. The input list is [1, 2, 3].
identityTransformationreturns the list[1, 2, 3]multTwoAndThenAddOneTransformationreturns the list[3, 5, 7]squareAndThenGetNextEvenNumberTransformationreturns the result list[2, 6, 10]