Skip to content
This repository has been archived by the owner on Jan 22, 2023. It is now read-only.

Commit

Permalink
refactor(range): defer to rangeBy for range validation
Browse files Browse the repository at this point in the history
  • Loading branch information
David Zukowski committed May 29, 2017
1 parent 55e7aa7 commit 0fc3700
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
7 changes: 1 addition & 6 deletions src/range.js
Expand Up @@ -16,10 +16,5 @@ import rangeBy from './rangeBy'
* range(0, -5) // => [0, -1, -2, -3, -4]
*/
export default _defn('range', function (start, end) {
if (start < end) return rangeBy(1, start, end)
if (start > end) return rangeBy(-1, start, end)
throw new Error(
'The `start` value provided to `range` must be greater than or less ' +
'than the `end` value. Received the same value for both: ' + start + '.'
)
return rangeBy(start < end ? 1 : -1, start, end)
})
8 changes: 2 additions & 6 deletions tests/range.spec.js
Expand Up @@ -17,10 +17,6 @@ test('returns an array of numbers stepped by -1 when start > end', (t) => {
t.deepEqual(range(0, -10), [0, -1, -2, -3, -4, -5, -6, -7, -8, -9])
})

test('throws when end === start', (t) => {
t.throws(
() => range(1, 1),
'The `start` value provided to `range` must be greater than or less than ' +
'the `end` value. Received the same value for both: 1.'
)
test('returns an empty array when start === end', (t) => {
t.deepEqual(range(5, 5), [])
})

0 comments on commit 0fc3700

Please sign in to comment.