Skip to content

Instantly share code, notes, and snippets.

@railsstudent
Created January 30, 2017 15:00
Show Gist options
  • Save railsstudent/7e722059e16efbdbba3350dc718093c3 to your computer and use it in GitHub Desktop.
Save railsstudent/7e722059e16efbdbba3350dc718093c3 to your computer and use it in GitHub Desktop.
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