Skip to content

Commit fdb733b

Browse files
committed
fix: range creates array with only one element when end is 0
- because 0 is falsy the start was overwritten with 0 when end is 0 resulting in the array [0] - explicitly check for end !== undefined to prevent this - add test case where end is 0
1 parent 4cab190 commit fdb733b

6 files changed

Lines changed: 6 additions & 5 deletions

File tree

cdn/radash.esm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ const unique = (array, toKey) => {
206206
};
207207
function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
208208
const mapper = isFunction(valueOrMapper) ? valueOrMapper : () => valueOrMapper;
209-
const start = end ? startOrLength : 0;
209+
const start = end !== void 0 ? startOrLength : 0;
210210
const final = end ?? startOrLength;
211211
for (let i = start; i <= final; i += step) {
212212
yield mapper(i);

cdn/radash.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ var radash = (function (exports) {
209209
};
210210
function* range(startOrLength, end, valueOrMapper = (i) => i, step = 1) {
211211
const mapper = isFunction(valueOrMapper) ? valueOrMapper : () => valueOrMapper;
212-
const start = end ? startOrLength : 0;
212+
const start = end !== void 0 ? startOrLength : 0;
213213
const final = end ?? startOrLength;
214214
for (let i = start; i <= final; i += step) {
215215
yield mapper(i);

cdn/radash.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "radash",
3-
"version": "12.1.1",
3+
"version": "12.1.2",
44
"description": "Functional utility library - modern, simple, typed, powerful",
55
"main": "dist/cjs/index.cjs",
66
"module": "dist/esm/index.mjs",

src/array.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ export function* range<T = number>(
325325
step: number = 1
326326
): Generator<T> {
327327
const mapper = isFunction(valueOrMapper) ? valueOrMapper : () => valueOrMapper
328-
const start = end ? startOrLength : 0
328+
const start = end !== undefined ? startOrLength : 0
329329
const final = end ?? startOrLength
330330
for (let i = start; i <= final; i += step) {
331331
yield mapper(i)

src/tests/array.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ describe('array module', () => {
404404
assert.deepEqual(toList(_.range(0, 4)), [0, 1, 2, 3, 4])
405405
assert.deepEqual(toList(_.range(3)), [0, 1, 2, 3])
406406
assert.deepEqual(toList(_.range(0, 3)), [0, 1, 2, 3])
407+
assert.deepEqual(toList(_.range(-3, 0)), [-3, -2, -1, 0])
407408
assert.deepEqual(toList(_.range(0, 3, 'y')), ['y', 'y', 'y', 'y'])
408409
assert.deepEqual(toList(_.range(0, 3, () => 'y')), ['y', 'y', 'y', 'y'])
409410
assert.deepEqual(toList(_.range(0, 3, i => i)), [0, 1, 2, 3])

0 commit comments

Comments
 (0)