const seatingChart = [
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'],
];
function allocateSeats(numPeople) {
if (numPeople === 4) {
for (let index = 0;index < seatingChart.length;index++) {
if (seatingChart[index][2] !== 'X' && seatingChart[index][3] !== 'X' && seatingChart[index][4] !== 'X' && seatingChart[index][5] !== 'X') {
seatingChart[index][2] = 'X';
seatingChart[index][3] = 'X';
seatingChart[index][4] = 'X';
seatingChart[index][5] = 'X';
break;
} else if (seatingChart[index][0] !== 'X' && seatingChart[index][1] !== 'X' && seatingChart[index][6] !== 'X' && seatingChart[index][7] !== 'X') {
seatingChart[index][0] = 'X';
seatingChart[index][1] = 'X';
seatingChart[index][6] = 'X';
seatingChart[index][7] = 'X';
break;
}
}
}
if (numPeople === 3) {
for (let index = 0;index < seatingChart.length;index++) {
if (seatingChart[index][2] !== 'X' && seatingChart[index][3] !== 'X' && seatingChart[index][4] !== 'X') {
seatingChart[index][2] = 'X';
seatingChart[index][3] = 'X';
seatingChart[index][4] = 'X';
break;
}
}
}
if (numPeople === 2) {
for (let index = 0;index < seatingChart.length;index++) {
if (seatingChart[index][0] !== 'X' && seatingChart[index][1] !== 'X') {
seatingChart[index][0] = 'X';
seatingChart[index][1] = 'X';
break;
} else if (seatingChart[index][6] !== 'X' && seatingChart[index][7] !== 'X') {
seatingChart[index][6] = 'X';
seatingChart[index][7] = 'X';
break;
}
}
}
if (numPeople === 1) {
seatingChart.filter(i => { debugger; });
let isBreak = false;
for (let i = 0;i < seatingChart.length;i++) {
for (let j = 0;j < seatingChart[i].length;j++) {
if (seatingChart[i][j] !== 'X') {
seatingChart[i][j] = 'X';
isBreak = true;
break;
}
}
if (isBreak) {
break;
}
}
}
console.log(seatingChart);
}
Here's a solution in JS.