From fb598b0270a4a87c68a15ce340649fa18de1d64f Mon Sep 17 00:00:00 2001 From: David Braun Date: Wed, 24 Apr 2019 10:51:00 -0400 Subject: [PATCH] Make `slice` handle case of no start provided. --- lib/index.js | 2 +- test/index.js | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/index.js b/lib/index.js index 4981957..f2629c2 100644 --- a/lib/index.js +++ b/lib/index.js @@ -255,7 +255,7 @@ const Channel = function(length = 0) { return promise; }, - slice: (start, end = Infinity) => { + slice: (start = 0, end = Infinity) => { const output = Channel(); (async () => { diff --git a/test/index.js b/test/index.js index 7328319..4813f4d 100644 --- a/test/index.js +++ b/test/index.js @@ -399,6 +399,15 @@ describe(`Channel object`, function() { }); describe(`slice`, function() { + it(`no start`, async function() { + assert.deepEqual( + await Channel.of(0, 1, 2) + .slice() + .values(), + [0, 1, 2] + ); + }); + it(`start`, async function() { assert.deepEqual( await Channel.of(0, 1, 2) @@ -417,7 +426,7 @@ describe(`Channel object`, function() { ); }); - it(`start after end of channel`, async function() { + it(`starts after end of channel`, async function() { assert.deepEqual( await Channel.of(0, 1, 2) .slice(10)