Mapping array values with constructors
Syntactic sugar on the Array prototype’s map function and type constructors being functions allow us to quickly map values from one type to another.
Read fire tipIf we use a condition to choose which of two functions to call with the same parameters, we can use a ternary operator to remove some repetition.
// Regardless of which function we pick, we always pass 'martini' to it.
if (isJamesBond) {
shake('martini')
} else {
stir('martini')
}
// Because the parameter stays the same, we can select the function with a
// ternary operator instead.
(isJamesBond ? shake : stir)('martini')
Syntactic sugar on the Array prototype’s map function and type constructors being functions allow us to quickly map values from one type to another.
Read fire tip