diff --git a/src/slice.js b/src/slice.js index a777c51..9470b3b 100644 --- a/src/slice.js +++ b/src/slice.js @@ -91,6 +91,7 @@ class Slice { const start = this.start == null ? undefined : this.start; const stop = this.stop == null ? undefined : this.stop; extracted = array.slice(start, stop); + extracted = !Array.isArray(extracted) ? extracted.split('') : extracted; } else { extracted = this.indices(array) .map(index => array[index]); diff --git a/test/test-slice-string.js b/test/test-slice-string.js index 0435f2a..7c36d77 100644 --- a/test/test-slice-string.js +++ b/test/test-slice-string.js @@ -65,10 +65,17 @@ describe('SliceString', () => { assert(output == expectedOutput); }); - it('should extract the odd elements from an array', () => { + it('should extract the odd elements from a string', () => { const input = new SliceString('hello'); const expectedOutput = 'el'; const output = input[[1,,2]]; assert(output == expectedOutput); }); + + it('should extract the range from a string', () => { + const input = new SliceString('hello'); + const expectedOutput = 'ell'; + const output = input[[1,4]]; + assert(output == expectedOutput); + }); });