From 2bba816823c9b83cd1224e1209847cc759b11dec Mon Sep 17 00:00:00 2001 From: Yangshun Tay Date: Tue, 13 Feb 2018 19:46:42 -0800 Subject: [PATCH] Fix HOF answer --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 676c2ec96..4ceb7bad3 100644 --- a/README.md +++ b/README.md @@ -1474,15 +1474,17 @@ TODO ### What is the definition of a higher-order function? -A higher-order function is any function that takes another function as a parameter, which it uses to operate on some data, or returns a function as a result. Higher-order functions are meant to abstract some operation that is performed repeatedly. The classic example of this is `map`, which takes an array and a function as arguments. `map` then uses this function to transform each item in the array, returning a new array with the transformed data. Other popular examples in JavaScript are `forEach`, `filter`, and `reduce`. A higher-order function doesn't just need to be manipulating arrays as there are many use cases for returning a function from another function. `Array.prototype.bind` is one such example in JavaScript. +A higher-order function is any function that takes one or more functions as arguments, which it uses to operate on some data, and/or returns a function as a result. Higher-order functions are meant to abstract some operation that is performed repeatedly. The classic example of this is `map`, which takes an array and a function as arguments. `map` then uses this function to transform each item in the array, returning a new array with the transformed data. Other popular examples in JavaScript are `forEach`, `filter`, and `reduce`. A higher-order function doesn't just need to be manipulating arrays as there are many use cases for returning a function from another function. `Array.prototype.bind` is one such example in JavaScript. **Map** -Let say we have an array of names which we need to transform each element to uppercase string. +Let say we have an array of names which we need to transform each string to uppercase. -`const names = ['irish', 'daisy', 'anna']`; +```js +const names = ['irish', 'daisy', 'anna']; +``` -The imperative way will be like: +The imperative way will be as such: ```js const transformNamesToUppercase = function(names) { @@ -1495,7 +1497,7 @@ const transformNamesToUppercase = function(names) { transformNamesToUppercase(names); // ['IRISH', 'DAISY', 'ANNA'] ``` -Use `.map(transformerFn)` makes it simpler, easy to reason about and declarative. +Use `.map(transformerFn)` makes the code shorter and more declarative. ```js const transformNamesToUppercase = function(names) {