Skip to content

Commit

Permalink
feat(range): support negative steps
Browse files Browse the repository at this point in the history
  • Loading branch information
innocenzi committed Oct 12, 2023
1 parent b1c7ff8 commit ed52261
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/array.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ it('range', () => {
expect(range(2)).toEqual([0, 1])
expect(range(2, 5)).toEqual([2, 3, 4])
expect(range(2, 10, 2)).toEqual([2, 4, 6, 8])
expect(range(3, 0, -1)).toEqual([3, 2, 1])
})

it('partition', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function range(...args: any): number[] {

const arr: number[] = []
let current = start
while (current < stop) {
while (step > 0 ? (current < stop) : (current > stop)) {
arr.push(current)
current += step || 1
}
Expand Down

0 comments on commit ed52261

Please sign in to comment.