Permutations of Array

Advanced

Description

Hello, young coder! Today, you have a magical task to solve. We want to generate all possible permutations of a list of items. Imagine you have a set of colorful blocks on your table and you want to see all the different ways you can arrange these blocks! This is what permutations are all about.

A permutation of an array is a different way to arrange all the elements in that array. For example, if you have an array with the elements [1, 2, 3], some permutations would be [1, 2, 3], [1, 3, 2], [2, 1, 3], etc.

Your mission is to write a function that, given a list of items, returns a list of all possible permutations of the array.

Examples

Here's how you should implement the function:

permutations_of_array([1, 2, 3])

Should return:

[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]

Another example:

permutations_of_array(["a", "b"])

Should return:

[["a", "b"], ["b", "a"]]

Note: The order of permutations does not have to match exactly, but all possible permutations should be present.

Geek
Inputs

Arg 1:

[1,2,3]
Expected Output
[[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
Actual Output
Permutations of Array [advanced] | Coding for Kids