Skip to content
Advertisement

Permutation on arrays without duplicate and fixed length

I’m having trouble figuring out how to generate a combination of values.

Given:

JavaScript

should generate:

JavaScript

It generates a unique combination for all the items in the array. Basically, the length of the array for each item is Math.round(items.length / 2).

Any help would be greatly appreciated.

Advertisement

Answer

You could take a straight forward approach and iterate the array and get the parts of the rest array by respecting the wanted length.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement