0.0.4 • Published 8 years ago
number-partition v0.0.4
number-partition
Partition a natural number, x, into n randomly-sized partitions such that the sum of the partitions is equal to x.
Install
npm install number-partitionSyntax
This function is curried by default.
const partitions = partition(n)(x);Parameters
n (number)
The number of partitions to generate.  
x (number)
The number to partition.
Usage
const partition = require('number-partition');
partition(3)(100);
// [4, 54, 42]
partition(3)(100);
// [53, 37, 10]
partition(5)(190);
// [108, 23, 43, 1, 15]
partition(5)(190);
// [ 9, 4, 115, 47, 15 ]
const intoFive = partition(5);
intoFive(512);
// [ 488, 18, 2, 2, 2 ]
intoFive(512);
// [ 281, 83, 77, 18, 53 ]Running tests
npm install
npm testThe tests are written with Mocha using Chai as an assertion library.