-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Create tests22 #930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Create tests22 #930
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
|
|
||
| module.exports = splitInteger; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 returnresultas is.