Created
January 30, 2017 15:00
-
-
Save railsstudent/7e722059e16efbdbba3350dc718093c3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function sierpinski(n) { | |
if (n === 0) { | |
return 'L'; | |
} | |
let tri = sierpinski(n - 1); | |
let triRows = tri.split('\n'); | |
let gap = 2 * triRows.length - 1; | |
let arr = triRows.reduce((arr, r) => { | |
arr.push(r + ' '.repeat(gap) + r); | |
gap -= 2; | |
return arr; | |
}, []); | |
return tri + '\n' + arr.join('\n') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment