> For the complete documentation index, see [llms.txt](https://algorithm.prettylog.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://algorithm.prettylog.com/algorithm-problems/algoexpert/medium/permutations.md).

# Permutations -

<figure><img src="/files/GXRxIyfqpYJfVxD2UmtQ" alt=""><figcaption></figcaption></figure>

* bad
* n^n, n\*n!

```jsx
let permutations;
function getPermutations(arr) {
  permutations = [];

  for (const n of arr) {
    permutate(arr, [n]);
  }
  
  return permutations;
}

function permutate(arr, currArr = []) {
  if (arr.length === currArr.length) {
    permutations.push(currArr);
    return;
  }
  
  for (const n of arr) {
    if (currArr.includes(n)) continue;
    permutate(arr, [...currArr, n]);
  }
  
  return;
}

// Do not edit the line below.
exports.getPermutations = getPermutations;
```
