diff --git a/src/app/core/utils/functions.spec.ts b/src/app/core/utils/functions.spec.ts index 9d29ba1077..59efa7d9e1 100644 --- a/src/app/core/utils/functions.spec.ts +++ b/src/app/core/utils/functions.spec.ts @@ -27,12 +27,15 @@ describe('Functions', () => { expect(arraySlices(arr, 6)).toEqual([[1, 2, 3, 4, 5, 6]]); }); - it('should return truncated result for length 8', () => { - expect(arraySlices(arr, 8)).toBeEmpty(); + it('should return correctly sliced arrays of length 8', () => { + expect(arraySlices(arr, 8)).toEqual([[1, 2, 3, 4, 5, 6]]); }); - it('should return truncated result for length 4', () => { - expect(arraySlices(arr, 4)).toEqual([[1, 2, 3, 4]]); + it('should return correctly sliced arrays of length 4', () => { + expect(arraySlices(arr, 4)).toEqual([ + [1, 2, 3, 4], + [5, 6], + ]); }); it('should return undefined when input is undefined or empty', () => { diff --git a/src/app/core/utils/functions.ts b/src/app/core/utils/functions.ts index b2a8876a75..77aae083bc 100644 --- a/src/app/core/utils/functions.ts +++ b/src/app/core/utils/functions.ts @@ -8,7 +8,7 @@ import { Observable, isObservable, of } from 'rxjs'; export const arraySlices = (input: T[], sliceLength: number): T[][] => input && input.length && sliceLength > 0 ? // determine slice indexes - range(0, Math.floor(input.length / sliceLength)) + range(0, Math.ceil(input.length / sliceLength)) // cut array into slices .map(n => input.slice(n * sliceLength, (n + 1) * sliceLength)) : undefined;