A usability study wants to show dashboard widgets to participants in every possible order to cancel out ordering bias. Write permutations(items), which returns all orderings of items.
All items are distinct.
permutations(['chart', 'table', 'map']);
// [
// ['chart', 'table', 'map'],
// ['chart', 'map', 'table'],
// ['table', 'chart', 'map'],
// ['table', 'map', 'chart'],
// ['map', 'chart', 'table'],
// ['map', 'table', 'chart'],
// ]
permutations([1]); // [[1]]
permutations([]); // [[]] (one ordering of nothing)
items.0 ≤ items.length ≤ 8 (8! = 40,320 permutations).items can contain duplicates and you must not return duplicate orderings?Spotted a mistake or a rights concern? Report an issue