diff --git a/src/splitInteger.js b/src/splitInteger.js index d3da7485..a438062f 100644 --- a/src/splitInteger.js +++ b/src/splitInteger.js @@ -7,6 +7,16 @@ * @returns {number[]} */ function splitInteger(value, numberOfParts) { + if (value < numberOfParts) { + const output = []; + + for (let i = 0; i < numberOfParts; i++) { + output[i] = 0; + } + + return output; + } + const parts = []; let rest = value; diff --git a/src/splitInteger.test.js b/src/splitInteger.test.js index a610317d..35675f38 100644 --- a/src/splitInteger.test.js +++ b/src/splitInteger.test.js @@ -1,21 +1,33 @@ 'use strict'; -const splitInteger = require('./splitInteger'); +const splitInteger = require('./splitInteger.js'); test(`should split a number into equal parts if a value is divisible by a numberOfParts`, () => { + const value = [8, 8, 8, 8, 8, 8, 8, 8]; + const recived = splitInteger(64, 8); + expect(value).toEqual(recived); }); test(`should return a part equals to a value when splitting into 1 part`, () => { + const value = [9]; + const recived = splitInteger(9, 1); + expect(value).toEqual(recived); }); test('should sort parts ascending if they are not equal', () => { + const value = [5, 6, 6, 6]; + const recived = splitInteger(23, 4); + expect(value).toEqual(recived); }); test('should add zeros if value < numberOfParts', () => { + const value = [0, 0, 0, 0]; + const recived = splitInteger(3, 4); + expect(value).toEqual(recived); });