Derive every possible combination of elements in array
问题 Given an array and a length, I want to derive every possible combination of elements (non-repeating) at the specific length. So given an array of: arr = ['a','b','c','d'] and a length of 3, I'm after a function that outputs a 2-dimensional array as follows: result = [ ['a','b','c'], ['b','c','a'], ['c','a','b'], . . . etc. ] I've tried tackling this and have had a deal of difficulty. 回答1: The following code uses a brute-force approach. It generates every permutation of every combination of