Quick Start - adamjgrant/permutations GitHub Wiki

Quick Start

  1. Make sure you have Node installed and download the repo to get started.
  2. Add Permutation files to the project root or in a separate folder in the project. a. To get a random permutation, node random <relative path without .json>. i. For example, to run the weather example, node random examples/weather. b. To get all permutations, run the same command but with node index.

Include JS

const tree = new Permute(data, true);
const permutations = tree.one; // One permutation
console.log(permutations);

Create a permutation structure

The simplest permutation is

{ "main": ["a"] }

Which produces one permutation, a.

Adding more to the array produces

{ "main": ["a", "b"] }
a
b

Branching

In the "main" object, simply create an array and nest another array as the last item to expand the permutation set.

When using a string, the script will take all variations generated so far and add just that string. This is basically equivalent to an array with only one item.

When using a string, the script will create a fractal of the variations generated so far and add each variation, then continue on each fractal branch

{ "main": [ "a", "b", [ "c" ] ] }
ac
bc

This can be done recursively to produce more complex permutations, like in the weather example.

{
  "main": [
    "it's ", [
      "windy", "still", "blustery", [
        ", ", [
          "cloudy", "partly cloudy", "clear skies", [
            ", and ", [
              "5%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%", [
                " chance of precipitation."
              ]
            ]
          ]
        ]
      ]
    ]
  ]
}

These are just the basics. There is much more you can do with the permutation generator. See the other topics in the Pages menu to learn more.