diff --git a/src/splitInteger.js b/src/splitInteger.js index d3da7485..1b6eabe7 100644 --- a/src/splitInteger.js +++ b/src/splitInteger.js @@ -17,7 +17,7 @@ function splitInteger(value, numberOfParts) { rest -= part; } - return parts; + return parts.sort((a, b) => a - b); } module.exports = splitInteger; diff --git a/src/splitInteger.test.js b/src/splitInteger.test.js index a610317d..3c0c081e 100644 --- a/src/splitInteger.test.js +++ b/src/splitInteger.test.js @@ -4,18 +4,18 @@ const splitInteger = require('./splitInteger'); test(`should split a number into equal parts if a value is divisible by a numberOfParts`, () => { - + expect(splitInteger(8, 2)).toEqual([4, 4]); }); test(`should return a part equals to a value when splitting into 1 part`, () => { - + expect(splitInteger(1000, 1)).toHaveLength(1); }); test('should sort parts ascending if they are not equal', () => { - + expect(splitInteger(10, 3)).toEqual([3, 3, 4]); }); test('should add zeros if value < numberOfParts', () => { - + expect(splitInteger(4, 5)).toContain(0); });