Skip to content

Commit

Permalink
fix(Module): Add uniq and docs (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
beardedtim authored Apr 9, 2018
1 parent 1afad62 commit 5277e58
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* [reduce](#reduce)
* [set](#set)
* [T](#t)
* [uniq](#uniq)
* [uppercase](#uppercase)
* [view](#view)
* [zip](#zip)
Expand Down Expand Up @@ -554,6 +555,21 @@ const nameLens = lensProp('name')
const updated = set(nameLens, 'Joh', data) // { name: 'John', age: 29 }
```

Sets the value at the location pointed to by the lens.

### uniq

```
uniq: Array<T> -> Array<T>
```

```
const arr = [1, 2, 3, 1]
uniq(arr) // [1, 2, 3]
```

Returns a copy of the passed in array, with only unique values.

### uppercase

```
Expand Down
19 changes: 19 additions & 0 deletions __tests__/modules/uniq.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import uniq from '../../modules/uniq'

describe('uniq', () => {
test('returns an array of unique values', () => {
const arr = [1, 2, 3, 4, 1]
const actual = uniq(arr)
const expected = [1, 2, 3, 4]

expect(actual).toEqual(expected)
})

test('returns a copy of the passed in array', () => {
const arr = [1, 2, 3]
const actual = uniq(arr)

expect(actual).not.toBe(arr)
expect(actual).toEqual(arr)
})
})
2 changes: 2 additions & 0 deletions modules/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ export { default as prop } from './prop'
export { default as propOr } from './propOr'
export { default as reduce } from './reduce'
export { default as set } from './set'
export { default as uniq } from './uniq'
export { default as uppercase } from './uppercase'
export { default as view } from './view'
export { default as zip } from './zip'
3 changes: 3 additions & 0 deletions modules/uniq.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const uniq = arr => Array.from(new Set(arr))

export default uniq

0 comments on commit 5277e58

Please sign in to comment.