Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
{
"name": "split-integer",
"version": "1.0.0",
"description": "Create tests for splitInteger function",
"description": "",
"main": "splitInteger.js",
"scripts": {
"init": "mate-scripts init",
"start": "mate-scripts start",
"lint": "mate-scripts lint",
"test:only": "mate-scripts test",
"update": "mate-scripts update",
"postinstall": "npm run update",
"test": "npm run lint && npm run test:only"
"test": "jest"
},
"author": "Mate academy",
"license": "GPL-3.0",
"devDependencies": {
"@mate-academy/eslint-config": "*",
"@mate-academy/scripts": "^0.9.7",
"eslint": "^5.16.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-node": "^8.0.1",
"jest": "^24.5.0"
},
"mateAcademy": {
"projectType": "javascript"
"jest": "^29.0.0"
}
}
13 changes: 13 additions & 0 deletions splitInteger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function splitInteger(value, numberOfParts) {
const base = Math.floor(value / numberOfParts);
const remainder = value % numberOfParts;

const result = Array(numberOfParts).fill(base);
for (let i = 0; i < remainder; i++) {
result[i]++;
}

return result.sort((a, b) => a - b);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorting the result here may violate the requirement if the task expects the larger parts (those with the extra 1) to come first. Please check the task description or checklist regarding the required order of the output. If order matters, remove the .sort((a, b) => a - b) and return result as is.

}

module.exports = splitInteger;
8 changes: 8 additions & 0 deletions splitInteger.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const splitInteger = require('./splitInteger');

test('splitInteger basic tests', () => {
expect(splitInteger(8, 1)).toEqual([8]);
expect(splitInteger(6, 2)).toEqual([3, 3]);
expect(splitInteger(17, 4)).toEqual([4, 4, 4, 5]);
expect(splitInteger(32, 6)).toEqual([5, 5, 5, 5, 6, 6]);
Comment on lines +6 to +7
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The expected output arrays have the larger numbers at the end, which may not match the output of the current implementation if it sorts the result. Please ensure that the implementation of splitInteger returns the parts in the correct order as expected by these tests.

});
Loading