Skip to content

Instantly share code, notes, and snippets.

@nukosuke
Created October 29, 2016 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nukosuke/39810fedead4b96385cd4457b87a5712 to your computer and use it in GitHub Desktop.
Save nukosuke/39810fedead4b96385cd4457b87a5712 to your computer and use it in GitHub Desktop.
co3496558でやってたピラミッド作る問題
function createPyramid(height){
return Array.from({length: height}, (v,k) => k+1)
.map(r => ' '.repeat(height-r).concat('*'.repeat(r*2-1)))
.join('\n');
}
console.log(createPyramid(10));
@nukosuke
Copy link
Author

for文で書くとこうかな

function createPyramid(height) {
  var pyramid = [];
  for(var i=1; i<=height; i++) {
    pyramid.push( ' '.repeat(height-i) + '*'.repeat(i*2-1) );
  }
  return pyramid.join('\n');
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment