Skip to content

Commit

Permalink
fix: only run sortArray on string[] (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and keithamus committed Jan 9, 2020
1 parent 3b523ff commit 1ce4d77
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const hasOwnProperty = (object, property) =>
Object.prototype.hasOwnProperty.call(object, property)
const pipe = fns => x => fns.reduce((result, fn) => fn(result), x)
const onArray = fn => x => (Array.isArray(x) ? fn(x) : x)
const uniq = onArray(xs => xs.filter((x, i) => i === xs.indexOf(x)))
const sortArray = onArray(array => [...array].sort())
const onStringArray = fn => x =>
Array.isArray(x) && x.every(item => typeof item === 'string') ? fn(x) : x
const uniq = onStringArray(xs => xs.filter((x, i) => i === xs.indexOf(x)))
const sortArray = onStringArray(array => [...array].sort())
const uniqAndSortArray = pipe([uniq, sortArray])
const isPlainObject = x =>
x && Object.prototype.toString.call(x) === '[object Object]'
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1ce4d77

Please sign in to comment.