Skip to content

Instantly share code, notes, and snippets.

@idrakimuhamad
Last active May 10, 2016 04:49
Show Gist options
  • Save idrakimuhamad/bfad91ea33fc114b1679ced053e0cb83 to your computer and use it in GitHub Desktop.
Save idrakimuhamad/bfad91ea33fc114b1679ced053e0cb83 to your computer and use it in GitHub Desktop.
Print 1 - 15 in rows of 5
var a = [];
for (var i = 0; i < 5; i++) {
if (i == 0) {
a.push(i + 1);
} else {
for (var j = 0; j < i; j++) {
if (j == 0) {
a[j] += 1 + (i-1);
} else {
a[j] = a[j-1] + 1;
}
}
a.push(a[i - 1] + 1);
}
console.log(a);
}
// 1
// 2 3
// 4 5 6
// 7 8 9 10
// 11 12 13 14 15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment