Skip to content

Commit

Permalink
Update transform-array.md
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelCurrin authored Jul 29, 2024
1 parent 06f38bb commit 2b5131f
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions cheatsheets/javascript/general/data-structures/transform-array.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,21 @@ const upper = letters.map(x => upper(x))

### Promises

Warning - when using `.then` promise chains, it does not work to just pass a function. you need to wrap that in a function.
Calling `String.upper()` on an array of items in a promise:

```javascript
Promise.resolve([ 'a', 'b', 'c' ] )
.then(x => x.upper())
.then(x => x.toUpperCase())
// ['A', 'B', 'C']
```

When using `.then` promise chains with `map`, be careful about how you pass functions.

In other languages, you could use something like `.then(console.log)` if there is a single paramter but for JS you need to specify a variable. e.g. `.then(x => console.log(x))`





## Comparison with Functional Programming

Expand Down

0 comments on commit 2b5131f

Please sign in to comment.