static k_combinations(set, k) {
  	var i, j, combs, head, tailcombs;

  	if (k > set.length || k <= 0) {
  		return [];
  	}

  	if (k === set.length) {
  		return [set];
  	}

  	if (k === 1) {
  		combs = [];
  		for (i = 0; i < set.length; i++) {
  			combs.push([set[i]]);
  		}
  		return combs;
  	}

  	// Assert {1 < k < set.length}

  	combs = [];
  	for (i = 0; i < set.length - k + 1; i++) {
  		head = set.slice(i, i+1);
  		tailcombs = Combinations.k_combinations(set.slice(i + 1), k - 1);
  		for (j = 0; j < tailcombs.length; j++) {
  			combs.push(head.concat(tailcombs[j]));
  		}
  	}
  	return combs;
  }
K-combinations

Get k-sized combinations of elements in a set.

Usage:
  k_combinations(set, k)

Parameters:
  set: Array of objects of any type. They are treated as unique.
  k: size of combinations to search for.

Return:
  Array of found combinations, size of a combination is k.

Examples:

  k_combinations([1, 2, 3], 1)
  -> [[1], [2], [3]]

  k_combinations([1, 2, 3], 2)
  -> [[1,2], [1,3], [2, 3]

  k_combinations([1, 2, 3], 3)
  -> [[1, 2, 3]]

  k_combinations([1, 2, 3], 4)
  -> []

  k_combinations([1, 2, 3], 0)
  -> []

  k_combinations([1, 2, 3], -1)
  -> []

  k_combinations([], 0)
  -> []