From 46c1598540f15552eae99463afaa8e5f8548cca5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81abucki?= Date: Fri, 16 Jan 2026 20:06:04 +0100 Subject: [PATCH 1/3] Solution --- src/customs.js | 41 ++++++++++++++++++++++++++++++++++++++++ src/splitInteger.test.js | 18 ++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/customs.js diff --git a/src/customs.js b/src/customs.js new file mode 100644 index 00000000..1cf6df53 --- /dev/null +++ b/src/customs.js @@ -0,0 +1,41 @@ +'use strict'; + +function toBeSortedAscending(arr) { + if (hasRemainder(arr) === false) { + return arr.every((val, i) => i === 0 || arr[i - 1] <= val); + } +} + +function hasRemainder(number, parts) { + return number % parts === 0; +} + +function hasSpilitEqual(result, number, parts) { + const remainder = hasRemainder(number, parts); + const length = result.length === parts; + const equality + = result[0] === result[result.length - 1] + && result.every((e) => e === result[0]); + + return remainder ? (length ? equality : false) : false; +} + +function hasEqualValueToNumber(result, number) { + return result[0] === number ? result : false; +} + +function zerosCounts(number, parts) { + return Math.max(0, parts - number); +} + +function howManyZerosInArray(result) { + return result.reduce((acc, val) => (val === 0 ? acc + 1 : acc), 0); +} + +module.exports = { + toBeSortedAscending, + hasSpilitEqual, + hasEqualValueToNumber, + zerosCounts, + howManyZerosInArray, +}; diff --git a/src/splitInteger.test.js b/src/splitInteger.test.js index a610317d..6eadcfa2 100644 --- a/src/splitInteger.test.js +++ b/src/splitInteger.test.js @@ -1,21 +1,39 @@ 'use strict'; +const { + toBeSortedAscending, + hasSpilitEqual, + hasEqualValueToNumber, + zerosCounts, + howManyZerosInArray, +} = require('./customs'); + const splitInteger = require('./splitInteger'); test(`should split a number into equal parts if a value is divisible by a numberOfParts`, () => { + const result = splitInteger(34, 2); + const resultOfCustoms = hasSpilitEqual(result, 34, 2); + expect(resultOfCustoms).toEqual(true); }); test(`should return a part equals to a value when splitting into 1 part`, () => { + const result = splitInteger(34, 1); + const resultOfCustoms = hasEqualValueToNumber(result, 34); + expect(resultOfCustoms).toEqual([34]); }); test('should sort parts ascending if they are not equal', () => { + const result = splitInteger(34, 5); + expect(toBeSortedAscending(result)).toBe(true); }); test('should add zeros if value < numberOfParts', () => { + const result = howManyZerosInArray(splitInteger(2, 4)); + expect(zerosCounts(2, 4)).toBe(result); }); From 65ad90ed21fe5b4cb1ea9f6b07968a4875031797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81abucki?= Date: Fri, 16 Jan 2026 20:19:40 +0100 Subject: [PATCH 2/3] Re-run CI From e0a0a17482c5dfa552054e4a54785f584b5a97f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20=C5=81abucki?= Date: Fri, 16 Jan 2026 20:49:28 +0100 Subject: [PATCH 3/3] Solution with simply assertions --- src/customs.js | 6 ++++-- src/splitInteger.test.js | 31 ++++++++++++++----------------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/customs.js b/src/customs.js index 1cf6df53..39f725aa 100644 --- a/src/customs.js +++ b/src/customs.js @@ -1,9 +1,11 @@ 'use strict'; -function toBeSortedAscending(arr) { - if (hasRemainder(arr) === false) { +function toBeSortedAscending(arr, number, parts) { + if (hasRemainder(number, parts) === false) { return arr.every((val, i) => i === 0 || arr[i - 1] <= val); } + + return true; } function hasRemainder(number, parts) { diff --git a/src/splitInteger.test.js b/src/splitInteger.test.js index 6eadcfa2..29fec8c9 100644 --- a/src/splitInteger.test.js +++ b/src/splitInteger.test.js @@ -1,39 +1,36 @@ 'use strict'; const { - toBeSortedAscending, - hasSpilitEqual, + // toBeSortedAscending, + // hasSpilitEqual, hasEqualValueToNumber, - zerosCounts, - howManyZerosInArray, + // zerosCounts, + // howManyZerosInArray, } = require('./customs'); const splitInteger = require('./splitInteger'); test(`should split a number into equal parts if a value is divisible by a numberOfParts`, () => { - const result = splitInteger(34, 2); - const resultOfCustoms = hasSpilitEqual(result, 34, 2); - - expect(resultOfCustoms).toEqual(true); + expect(splitInteger(6, 2)).toEqual([3, 3]); }); test(`should return a part equals to a value when splitting into 1 part`, () => { - const result = splitInteger(34, 1); - const resultOfCustoms = hasEqualValueToNumber(result, 34); + const result = splitInteger(8, 1); + const resultOfCustoms = hasEqualValueToNumber(result, 8); - expect(resultOfCustoms).toEqual([34]); + expect(resultOfCustoms).toEqual([8]); }); test('should sort parts ascending if they are not equal', () => { - const result = splitInteger(34, 5); - - expect(toBeSortedAscending(result)).toBe(true); + // const result = splitInteger(17, 4); + // expect(toBeSortedAscending(result)).toBe(true); + expect(splitInteger(17, 4)).toEqual([4, 4, 4, 5]); }); test('should add zeros if value < numberOfParts', () => { - const result = howManyZerosInArray(splitInteger(2, 4)); - - expect(zerosCounts(2, 4)).toBe(result); + // const result = howManyZerosInArray(splitInteger(2, 4)); + // expect(zerosCounts(2, 4)).toBe(result); + expect(splitInteger(2, 4)).toEqual([0, 0, 1, 1]); });