From 3e4f07b993259e16197abb3e4d86d3c320b91352 Mon Sep 17 00:00:00 2001 From: Maciej Date: Mon, 14 Jul 2025 15:14:47 +0200 Subject: [PATCH 1/3] Solution --- src/splitInteger.js | 4 ++++ src/splitInteger.test.js | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/splitInteger.js b/src/splitInteger.js index d3da7485..3d957c9b 100644 --- a/src/splitInteger.js +++ b/src/splitInteger.js @@ -7,6 +7,10 @@ * @returns {number[]} */ function splitInteger(value, numberOfParts) { + if (value < numberOfParts) { + return [0]; + } + const parts = []; let rest = value; diff --git a/src/splitInteger.test.js b/src/splitInteger.test.js index a610317d..3898b844 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]; + const recived = splitInteger(3, 4); + expect(value).toEqual(recived); }); From ca3f10dfb96d313e49e5952395a81580a04ff31f Mon Sep 17 00:00:00 2001 From: Maciej Date: Mon, 14 Jul 2025 15:19:50 +0200 Subject: [PATCH 2/3] Fixed nr 1 --- src/splitInteger.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/splitInteger.test.js b/src/splitInteger.test.js index 3898b844..dfd8017f 100644 --- a/src/splitInteger.test.js +++ b/src/splitInteger.test.js @@ -4,7 +4,7 @@ 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 value = [8, 8, 8, 8, 8, 8, 8, 8]; const recived = splitInteger(64, 8); expect(value).toEqual(recived); From cb66dbb97786b6bde46a669ea7233dcaf10768e3 Mon Sep 17 00:00:00 2001 From: Maciej Date: Mon, 14 Jul 2025 15:53:48 +0200 Subject: [PATCH 3/3] Fixed nr 2 --- src/splitInteger.js | 8 +++++++- src/splitInteger.test.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/splitInteger.js b/src/splitInteger.js index 3d957c9b..a438062f 100644 --- a/src/splitInteger.js +++ b/src/splitInteger.js @@ -8,7 +8,13 @@ */ function splitInteger(value, numberOfParts) { if (value < numberOfParts) { - return [0]; + const output = []; + + for (let i = 0; i < numberOfParts; i++) { + output[i] = 0; + } + + return output; } const parts = []; diff --git a/src/splitInteger.test.js b/src/splitInteger.test.js index dfd8017f..35675f38 100644 --- a/src/splitInteger.test.js +++ b/src/splitInteger.test.js @@ -26,7 +26,7 @@ test('should sort parts ascending if they are not equal', () => { }); test('should add zeros if value < numberOfParts', () => { - const value = [0]; + const value = [0, 0, 0, 0]; const recived = splitInteger(3, 4); expect(value).toEqual(recived);