From 5277e58301237b57940b4f8e6c41adaa77845646 Mon Sep 17 00:00:00 2001 From: Tim Roberts Date: Mon, 9 Apr 2018 08:11:29 -0500 Subject: [PATCH] fix(Module): Add uniq and docs (#10) --- README.md | 16 ++++++++++++++++ __tests__/modules/uniq.test.js | 19 +++++++++++++++++++ modules/index.js | 2 ++ modules/uniq.js | 3 +++ 4 files changed, 40 insertions(+) create mode 100644 __tests__/modules/uniq.test.js create mode 100644 modules/uniq.js diff --git a/README.md b/README.md index 6737134..70b645c 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ * [reduce](#reduce) * [set](#set) * [T](#t) +* [uniq](#uniq) * [uppercase](#uppercase) * [view](#view) * [zip](#zip) @@ -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 -> Array +``` + +``` +const arr = [1, 2, 3, 1] +uniq(arr) // [1, 2, 3] +``` + +Returns a copy of the passed in array, with only unique values. + ### uppercase ``` diff --git a/__tests__/modules/uniq.test.js b/__tests__/modules/uniq.test.js new file mode 100644 index 0000000..87e3824 --- /dev/null +++ b/__tests__/modules/uniq.test.js @@ -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) + }) +}) \ No newline at end of file diff --git a/modules/index.js b/modules/index.js index f2ac2ad..868a0cf 100644 --- a/modules/index.js +++ b/modules/index.js @@ -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' \ No newline at end of file diff --git a/modules/uniq.js b/modules/uniq.js new file mode 100644 index 0000000..976e14f --- /dev/null +++ b/modules/uniq.js @@ -0,0 +1,3 @@ +const uniq = arr => Array.from(new Set(arr)) + +export default uniq \ No newline at end of file