Skip to content

Commit

Permalink
document methods
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Jan 21, 2022
1 parent 2cf3391 commit 26672c2
Showing 1 changed file with 64 additions and 2 deletions.
66 changes: 64 additions & 2 deletions packages/arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,15 @@ Here’s a list of available methods on a set instance:
[find](#find)
[findIndex](#findindex)
[findLast](#findlast)
[flatMap](#flatmap)
[has](#has)
[intersect](#intersect)
[isEmpty](#isempty)
[isNotEmpty](#isnotempty)
[join](#join)
[last](#last)
[length](#length)
[map](#map)
[max](#max)
[median](#median)
[min](#min)
Expand Down Expand Up @@ -350,6 +353,36 @@ const user = users.findLast(user => {
```
#### flatMap
- *added in version `2.0`*
The `flatMap` method invokes the callback function on each array item. The callback can modify and return the item resulting in a new array of modified items. Ultimately, `flatMap` flattens the mapped results one level deep:
```js
Arr.from([1, 2, 3]).flatMap(item => {
return [item, item]
})
// [1, 1, 2, 2, 3, 3]
```
#### has
- *added in `2.0`*
The `has` method returns `true` if the given `value` is present in the array, otherwise `false`:
```js
const users = Arr.from(['Marcus', 'Supercharge'])
users.has('Marcus')
// true
users.has('not-existent')
// false
```
#### intersect
- *added in `1.0`*
Expand All @@ -371,7 +404,7 @@ const intersection = ids.intersect(
The `isEmpty` method returns `true` if the array has no entries. Returns `false` if entries are present in the array:
```js
const items = Arr()
const items = Arr.from([])
items.isEmpty()
// true
Expand All @@ -383,13 +416,29 @@ items.isEmpty()
```
#### isMissing
- *added in `2.0`*
The `isMissing` method returns `true` if the given `value` is not present in the array, otherwise `false`:
```js
const users = Arr.from(['Marcus', 'Supercharge'])
users.isMissing('Marcus')
// false
users.isMissing('not-existent')
// true
```
#### isNotEmpty
- *added in `1.0`*
The `isNotEmpty` method returns `true` if entries are present in the array. Returns `false` if the array is empty:
```js
const items = Arr()
const items = Arr.from([])
items.isNotEmpty()
// false
Expand Down Expand Up @@ -465,6 +514,19 @@ Arr
```
#### map
- *added in version `2.0`*
The `map` method invokes the callback function on each array item and returns an array of transformed items. Because `map` returns an `Arr` instance, you could chain further operations:
```js
Arr.from([1, 2, 3]).map(item => {
return item * 10
})
// [ 10, 20, 30 ]
```
#### max
- *added in version `1.0`*
Expand Down

0 comments on commit 26672c2

Please sign in to comment.