Generates all possible combinations of the elements of an array (treated as unique).
https://gist.github.com/jpillora/4435759

@param {Array} collection The array with elements that should be combined.

@returns {Array} result An array of all possible combinations of elements of the original array.
function combinations( collection ) {
	/**
	 * A recursive function that iterates through all elements of an array to produce its combinations.
	 *
	 * @param {Array} xs The array to start accumulating with.
	 * @param {Array} array The array with elements that should be combined.
	 *
	 * @returns {Array} result An array of all possible combinations of elements of the original array.
	 */
	function acc( xs, array ) {
		const x = xs[ 0 ];

		if ( typeof x === "undefined" ) {
			return array;
		}

		for ( let i = 0, l = array.length; i < l; ++i ) {
			array.push( array[ i ].concat( x ) );
		}
		return acc( xs.slice( 1 ), array );
	}
	return acc( collection, [ [ ] ] ).slice( 1 ).concat( [ [] ] );
}