Skip to content

Instantly share code, notes, and snippets.

@risingBirdSong
Created December 29, 2019 03:34
Show Gist options
  • Select an option

  • Save risingBirdSong/90f195fd49ee31bc525498b5b60bb405 to your computer and use it in GitHub Desktop.

Select an option

Save risingBirdSong/90f195fd49ee31bc525498b5b60bb405 to your computer and use it in GitHub Desktop.
code war katas
function diamond(n : number){
if (n < 0 || n % 2 == 0){
return null;
}
let diamondstring = '';
for (let i = 1; i <= n; i += 2){
diamondstring += ' '.repeat((n - i) / 2) + '*'.repeat(i) + '\n';
}
for (let i = n - 2; i > 0; i -= 2){
diamondstring += ' '.repeat((n - i) / 2) + '*'.repeat(i) + '\n';
}
return diamondstring;
}
console.log(diamond(11))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment