heaps-algorithm

1.0.0 • Public • Published

heaps-algorithm

Heap's algorithm for generating permutations of an array.

installation

npm install heaps-algorithm

usage

This module exports a function, which returns an array of all permutations of the array passed to it.

var permutations = require('heaps-algorithm'),
    actual = permutations([1, 2, 3]),
    expected = [
      [ 1, 2, 3 ],
      [ 2, 1, 3 ],
      [ 3, 1, 2 ],
      [ 1, 3, 2 ],
      [ 2, 3, 1 ],
      [ 3, 2, 1 ]
    ];

assert.deepEqual(actual, expected); // true

Package Sidebar

Install

npm i heaps-algorithm

Weekly Downloads

39

Version

1.0.0

License

MIT

Last publish

Collaborators

  • phoenixstormcrow