-
Notifications
You must be signed in to change notification settings - Fork 256
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great refresh of the materials! I left of a couple comments, but nothing blocking - overall LGTM 👍
@@ -199,7 +199,9 @@ Result: | |||
|
|||
### Method chaining | |||
|
|||
The methods **map()**, **filter()** and **reduce()** each return a new array. This makes it possible to chain these methods and create a 'pipeline' of operations, to be applied in sequence. Let's take the last example, but now filtering out only those array elements for which the name starts with a 'J': | |||
The methods **map()** and **filter()** each return a new array. This makes it possible to chain these methods and create a 'pipeline' of operations, to be applied in sequence. The **reduce** method can return anything, including an array. If a **reduce** method returns something other than an array it can only be included at the end of an array method chain. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice clarification
fundamentals/promises.md
Outdated
@@ -70,44 +81,61 @@ If you are only interested in the error case, you can pass `null` for the first | |||
somePromise.then(null, onRejected) | |||
``` | |||
|
|||
or you can use a second method exposed by a promise object, which is just a short-hand for calling `then()` with `null` as its first argument: | |||
or you can use a second method exposed by a promise, which is just a short-hand for calling `then()` with `null` as its first argument: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point here. I also find this line a bit confusing, especially if you didn't know the details of how then()
works, might be worth further clarifying how catch()
is used in combination with then()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a .then()
before the .catch()
in the code snippet. Further down there is an explanation why .catch()
should be at the end of the chain, but I realise at this point in the text it remains a bit vague.
Made a tiny change to clarify that sentence: fa0387b |
Maybe clarify that Promise.reject(new Error('bad')).catch(() => 'good').then(console.log);
// outputs 'good' |
I have added a fundamental on the Event Loop and extended the promises fundamental. A minor correction to the map & filter fundamental, in that
reduce
does not return an array by default.In JS3, Week 9 I have interpreted the topic of 'Code Flow' as an explanation of the Event Loop, hence the added fundamental. Please comment if you are of a different opinion.
As promises and the Event Loop are complicated subjects to explain I would really appreciate a critical review of these fundamentals.