Skip to content

Instantly share code, notes, and snippets.

View rayhatfield's full-sized avatar

ray hatfield rayhatfield

View GitHub Profile

Keybase proof

I hereby claim:

  • I am rayhatfield on github.
  • I am rayhatfield (https://keybase.io/rayhatfield) on keybase.
  • I have a public key ASCCvANbUrpUTG-br3EFOmpIKmORG07KtvbXrorBToAedQo

To claim this, I am signing this object:

@rayhatfield
rayhatfield / permutations
Created May 2, 2019 20:57
generate all permutations of values in javascript
function permutations(values, length = values.length, result = values.map((v) => [v])) {
if (length < 2) {
return result;
}
return permutations(values, length - 1, result.reduce((acc, v) => {
values.forEach((n) => acc.push([...v, n]));
return acc;
}, []));
}