I have a number that is divisible by 4, e.g. 20. Now I need to create a string that looks as follows:
(1, 2, 3, 4), (5, 6, 7, 8), (9, 10, 11, 12), (13, 14, 15, 16), (17, 18, 19, 20)
So, all the numbers from 1 to 20, grouped in packages of 4, wrapped in parentheses, and everything separated by commas.
My current approach looks like this:
const placeholders = [];
for (let i = 0; i < events.length; i++) {
const base = i * 4 + 1;
placeholders.push(`(${base}, ${base + 1}, ${base + 2}, ${base + 3})`);
}
const result = placeholders.join(',');
Is there a way to do this a) more efficiently, and b) in a more readable way?