title: How to create an Array which contains unduplicated and not random numbers?
body: <p>I want to create a method in JavaScript which can generate an array containing non-random and non-duplicate numbers by using Tree structure.</p>
  
  <p>Assuming the method named <code>permutation()</code>, I just simply use</p>
  
  <pre><code>permutation(3)
  </code></pre>
  
  <p>and I will get an array which can iterate and each of them is</p>
  
  <pre><code>012 021 120 102 201 210
  </code></pre>
  
  <p>if I change the number 3 to 5 , it will generate an Array </p>
  
  <pre><code>012345 012354 etc...
  </code></pre>
  
  <p>and then I figure out I can use tree structure to build this kind of array like this:</p>
  
  <pre><code>root:     0      1      2 
          ↓   ↓  ↓   ↓  ↓   ↓
  depth1: 1   2  0   2  1   0
          ↓   ↓  ↓   ↓  ↓   ↓
  depth2: 2   1  1   0  0   1
  </code></pre>
  
  <p>then I just traverse all the nodes to get the result.</p>
  
  <p>It's same when the number is increased</p>
  
  <pre><code>root:           0               1   2   3   4   5   6....
          ↓   ↓   ↓   ↓   ↓   ↓
  depth1: 1   2   3   4   5   6
  
  etc....
  </code></pre>
  
  <p>The question is I don't know how could I construct such a tree in JavaScript? I don't know what kind of these questions named.</p>