From 8eeaeb4aa04829befafad427f9edac2e1ee84e54 Mon Sep 17 00:00:00 2001 From: Oleh Mysko Date: Sun, 1 Nov 2026 15:03:50 +0200 Subject: [PATCH 1/2] task solution --- src/splitInteger.js | 2 +- src/splitInteger.test.js | 28 ++++++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/splitInteger.js b/src/splitInteger.js index d3da7485..559cc9fa 100644 --- a/src/splitInteger.js +++ b/src/splitInteger.js @@ -19,5 +19,5 @@ function splitInteger(value, numberOfParts) { return parts; } - +console.log(splitInteger(1,5)) module.exports = splitInteger; diff --git a/src/splitInteger.test.js b/src/splitInteger.test.js index 24003dd5..d21f137d 100644 --- a/src/splitInteger.test.js +++ b/src/splitInteger.test.js @@ -3,11 +3,31 @@ const splitInteger = require('./splitInteger'); test(`should split a number into equal parts - if a value is divisible by a numberOfParts`, () => {}); + if a value is divisible by a numberOfParts`, () => { + expect(splitInteger(4,2)).toEqual([2,2]) + }); test(`should return a part equals to a value - when splitting into 1 part`, () => {}); + when splitting into 1 part`, () => { + const value = 4; + const part = 1; -test('should sort parts ascending if they are not equal', () => {}); + const result = splitInteger(value, part); -test('should add zeros if value < numberOfParts', () => {}); + let sum = 0; + + for (let i = 0; i < result.length; i++) { + sum += result[i]; + } + + expect(result.length).toBe(part); + expect(sum).toBe(value); +}); + +test('should sort parts ascending if they are not equal', () => { + expect(splitInteger(5,4)).toEqual([1,1,1,2]) +}); + +test('should add zeros if value < numberOfParts', () => { + expect(splitInteger(1,4)).toEqual([0,0,0,1]) +}); From dc58c2598084c6f145f58af3ac87f94499c926ad Mon Sep 17 00:00:00 2001 From: Oleh Mysko Date: Sun, 1 Nov 2026 18:23:53 +0200 Subject: [PATCH 2/2] task solution --- src/splitInteger.js | 2 +- src/splitInteger.test.js | 45 +++++++++++++++++++++++++--------------- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/splitInteger.js b/src/splitInteger.js index 559cc9fa..d3da7485 100644 --- a/src/splitInteger.js +++ b/src/splitInteger.js @@ -19,5 +19,5 @@ function splitInteger(value, numberOfParts) { return parts; } -console.log(splitInteger(1,5)) + module.exports = splitInteger; diff --git a/src/splitInteger.test.js b/src/splitInteger.test.js index d21f137d..5699b7c8 100644 --- a/src/splitInteger.test.js +++ b/src/splitInteger.test.js @@ -2,32 +2,43 @@ const splitInteger = require('./splitInteger'); -test(`should split a number into equal parts - if a value is divisible by a numberOfParts`, () => { - expect(splitInteger(4,2)).toEqual([2,2]) - }); -test(`should return a part equals to a value - when splitting into 1 part`, () => { - const value = 4; - const part = 1; +// Обов'язкові приклади з умови +test('should return [8] when splitting 8 into 1 part', () => { + expect(splitInteger(8, 1)).toEqual([8]); +}); + +test('should split 6 into 2 equal parts', () => { + expect(splitInteger(6, 2)).toEqual([3, 3]); +}); + +test('should split 17 into 4 ascending parts', () => { + expect(splitInteger(17, 4)).toEqual([4, 4, 4, 5]); +}); - const result = splitInteger(value, part); +test('should split 32 into 6 ascending parts', () => { + expect(splitInteger(32, 6)).toEqual([5, 5, 5, 5, 6, 6]); +}); - let sum = 0; +// Додаткові тести +test('should split a number into equal parts if divisible', () => { + expect(splitInteger(4, 2)).toEqual([2, 2]); +}); - for (let i = 0; i < result.length; i++) { - sum += result[i]; - } +test('should return the value when splitting into 1 part', () => { + const value = 4; + const numberOfParts = 1; + const result = splitInteger(value, numberOfParts); - expect(result.length).toBe(part); - expect(sum).toBe(value); + expect(result.length).toBe(numberOfParts); + expect(result[0]).toBe(value); }); test('should sort parts ascending if they are not equal', () => { - expect(splitInteger(5,4)).toEqual([1,1,1,2]) + expect(splitInteger(5, 4)).toEqual([1, 1, 1, 2]); }); test('should add zeros if value < numberOfParts', () => { - expect(splitInteger(1,4)).toEqual([0,0,0,1]) + expect(splitInteger(1, 4)).toEqual([0, 0, 0, 1]); }); +