You are looking for combination. In your case n=x and k=y.By borrowing code from here, you can visualize it by this way:
var x = 7;
var y = 3;
comb(y,x).forEach(function(item){
var tr = $('<tr>');
for(var i=0; i<x;++i){
tr.append('<td>');
}
var chunks = item.split(" ");
chunks.pop();
chunks.forEach(function(index){
tr.find("td").eq(+index).addClass("black");
});
$("table").append(tr);
});