Skip to content

divide an unknown integer into a given number of even parts — or at least as even as they can be.

Notifications You must be signed in to change notification settings

namwanza/divide-numbers-into-even-parts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

We need the ability to divide an unknown integer into a given number of even parts — or at least as even as they can be. The sum of the parts should be the original value, but each part should be an integer, and they should be as close as possible.

Complete the function so that it returns an array of an integer representing the parts. Ignoring the order of the parts, there is only one valid solution for each input to your function!

Also, there is no reason to test for edge cases: the input to your function will always be valid for this challenge.

Specification splitInteger(num, parts) Divides an integer into an "even as can be" number of parts.

Parameters num: Number - The number that should be split into equal parts parts: Number - The number of parts that the number should be split into

Return Value Array - An array of parts, with each index representing the part and the number contained within it representing the size of the part. The parts will be ordered from smallest to largest.

Examples num parts Return Value Completely even parts example 10 5 [2,2,2,2,2] Even as can be parts example 20 6 [3,3,3,3,4,4]

About

divide an unknown integer into a given number of even parts — or at least as even as they can be.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published