Changing functions in other ways
Let’s end this chapter by considering other sundry functions that provide results, such as new finders, decoupling methods from objects, and more. Our examples will include the following:
- Turning operations (such as adding with the
+
operator) into functions - Turning functions into promises
- Accessing objects to get the value of a property
- Turning methods into functions
- A better way of finding optimum values
Turning operations into functions
We have already seen several cases where we needed to write a function just to add or multiply a pair of numbers. For example, in the Summing an array section of Chapter 5, Programming Declaratively, we had to write code equivalent to the following:
const mySum = myArray.reduce( (x: number, y: number): number => x + y, 0 );
In the Working with ranges section of Chapter 5, Programming Declaratively, we wrote this to calculate a factorial:
...