Skip to content

Instantly share code, notes, and snippets.

@Luke-Rogerson
Created December 16, 2018 21:43
Show Gist options
  • Save Luke-Rogerson/d3bab27e4ac54536a1161ca42dc3c4b4 to your computer and use it in GitHub Desktop.
Save Luke-Rogerson/d3bab27e4ac54536a1161ca42dc3c4b4 to your computer and use it in GitHub Desktop.
Write a function that accepts a positive number N. The function should console log a step shape with N levels using the # character. Make sure the step has spaces on the right hand side!
// --- Examples
// steps(2)
// '# '
// '##'
// steps(3)
// '# '
// '## '
// '###'
// steps(4)
// '# '
// '## '
// '### '
// '####'
function steps(n, i = 1) {
if (i > n) return;
console.log('#'.repeat(i) + ' '.repeat(n - i));
steps(n, i + 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment