Skip to content

Commit 2f8c47b

Browse files
authored
Update README.md
1 parent fb18ee6 commit 2f8c47b

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

Diff for: README.md

+20-9
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,31 @@ Using `@supercharge/arrays` is pretty straightforward. The package exports a fun
5050
```js
5151
const { Arr } = require('@supercharge/arrays')
5252

53-
const hasItemsGreaterTen = Arr([1, 2, 3, 4, 5, 6])
54-
.map(value => value * 2) // [2, 4, 6, 8, 10, 12]
55-
.filter(value => value > 10) // [12]
56-
.isNotEmpty() // true
53+
const users = Arr.from([])
5754

55+
users.isEmpty()
56+
// true
5857

59-
// Only methods, no properties
60-
Arr([1, 2, 3]).length() // 3
58+
users
59+
.push({ id: 1, name: 'Marcus' })
60+
.push({ id: 2, name: 'Norman' })
61+
.push({ id: 3, name: 'Christian' })
6162

63+
users.isNotEmpty()
64+
// true
6265

63-
// Supports callbacks for `.includes`:
64-
Arr([1, 2, 3]).includes(value => {
65-
return value > 2
66+
users.length()
67+
// 3
68+
69+
const usernamesArray = users
70+
.map(user => user.name)
71+
.toArray()
72+
// [ 'Marcus', 'Norman', 'Christian' ]
73+
74+
const marcus = users.find(user => {
75+
return user.name === 'Marcus'
6676
})
77+
// { id: 1, name: 'Marcus' }
6778
```
6879

6980
Every method in the chain returns a `@supercharge/array` instance. This way, you can chain further methods without leaving the fluent interface. Call `.all()` to retrieve the plain JavaScript array.

0 commit comments

Comments
 (0)