Skip to content

Commit

Permalink
Merge pull request mouredev#3111 from manurgdev/main
Browse files Browse the repository at this point in the history
Reto mouredev#16 - TypeScript
  • Loading branch information
Roswell468 authored Apr 19, 2023
2 parents 8d77751 + 07846bb commit 029fba5
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Retos/Reto #16 - LA ESCALERA [Media]/typescript/manurgdev.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const createStairs = (n: number): string => {
if (n === 0) return '__';

let stairs = '';
const isAscending = n > 0;
const steps = Math.abs(n);
let spaces = ' '.repeat(steps);

stairs = isAscending ? `${spaces}_\n` : '_\n';
spaces = isAscending ? spaces.slice(0, -2) : ' ';

[...Array(steps)].forEach(() => {
stairs += isAscending ? `${spaces}_|\n` : `${spaces}|_\n`;
spaces = isAscending ? spaces.slice(0, -2) : `${spaces} `;
});

return stairs;
}

console.log(createStairs(6));
console.log(createStairs(0));
console.log(createStairs(-10));

0 comments on commit 029fba5

Please sign in to comment.