Given an array of numbers, partition them into a number of buckets, preserving order, where the ranges of each bucket are as close as possible.
Input: given an array of S non-negative numbers and an integer k (the number of partitions we want)
Output: Partition S into k ranges, so as to minimize the maximum sum over all the ranges.
var partition = ;;// returns [[1,2,3,4,5], [6,7], [8,9]]
Run tests with
npm run test or
tape test | faucet
Run benchmarks with
This library was a re-implementation of a horrendous coffeescript function that people used to use. Here are benchmark results when compared to that older implementation:
Winner: oursCompared with next highest (coffeescript), it's:91.73% faster12.09 times as fast1.08 order(s) of magnitude fasterA LOT FASTER