Skip to content

Commit 473e15f

Browse files
committed
Add task solution
1 parent 3fd8d93 commit 473e15f

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/splitInteger.test.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,24 @@ const splitInteger = require('./splitInteger');
44

55
test(`should split a number into equal parts
66
if a value is divisible by a numberOfParts`, () => {
7-
7+
expect(splitInteger(12, 3)).toEqual([4, 4, 4]);
8+
expect(splitInteger(6, 2)).toEqual([3, 3]);
89
});
910

1011
test(`should return a part equals to a value
1112
when splitting into 1 part`, () => {
12-
13+
expect(splitInteger(8, 1)).toEqual([8]);
14+
expect(splitInteger(25, 1)).toEqual([25]);
1315
});
1416

1517
test('should sort parts ascending if they are not equal', () => {
18+
const result = splitInteger(17, 4);
19+
const sorted = [...result].sort((a, b) => a - b);
1620

21+
expect(result).toEqual(sorted);
1722
});
1823

1924
test('should add zeros if value < numberOfParts', () => {
20-
25+
expect(splitInteger(3, 5)).toEqual([0, 0, 1, 1, 1]);
26+
expect(splitInteger(1, 3)).toEqual([0, 0, 1]);
2127
});

0 commit comments

Comments
 (0)