A Pen by idrakimuhamad on CodePen.
Last active
May 10, 2016 04:49
-
-
Save idrakimuhamad/bfad91ea33fc114b1679ced053e0cb83 to your computer and use it in GitHub Desktop.
Print 1 - 15 in rows of 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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