This is a `playground`

to test code. It runs a full `Node.js`

environment and already has all of `npm`

’s 400,000 packages pre-installed, including `@haensl/subset-sum`

with all `npm`

packages installed. **Try it out**:

var subsetSum = require("@haensl/subset-sum")

- all documents on RunKit are public
`require()`

any package directly from npm- use arrow functions, classes, template strings, and most of ES6
`await`

any promise instead of using callbacks (example)- create your own embedded
**node.js**snippets

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

Node.js module to compute solutions to the Coin changing problem, i.e. find combinations of integers from a given set of available integers that sum up to a desired result.

- Install the library

via `npm`

```
npm i -S @haensl/subset-sum
```

via `yarn`

```
yarn add @haensl/subset-sum
```

- Use the library in your code

```
const sumService = require('subset-sum');
const numbers = [1, 4, 2, 5, 1, 3];
const target = 6;
const solver = sumService.subsetSum(numbers, target);
for (let solution of solver) {
console.log(solution);
}
```

`subsetSum(numbers, target) => Generator`

Returns a generator that yields arrays of integers from `numbers`

that add up to `target`

.

`uniqueSolutions(solutions) => Array`

Filters `solutions`

for unique solutions.

`isSameSolution(solutionA, solutionB) => boolean`

Compares to solutions and determines if they are equal, i.e. contain the same integers. E.g. `[1, 1, 3, 1]`

and `[1, 3, 1, 1]`

are considered equal.

- package on npmhttps://npmjs.com/package/@haensl/subset-sum
- licenseMIT

RunKit is a free, in-browser JavaScript dev environment for prototyping **Node.js** code, with every **npm** package installed. Sign up to share your code.

Sign Up for Free