Skip to content

Commit

Permalink
Merge pull request #6211 from BRivasTorres/main
Browse files Browse the repository at this point in the history
Reto #16 - JavaScript
  • Loading branch information
kontroldev authored Jan 9, 2024
2 parents 00153dc + eba1780 commit 49ed33b
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Retos/Reto #16 - LA ESCALERA [Media]/javascript/BRivasTorres.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const createLadder = (n) => {
if(n === 0) return "__"

let steps = "_|"
let res = ""
let spaces = ""

if(n > 0) {
let i = 0
let temp = ""
while(n !== 0) {
temp += steps[i]
i === 1 ? temp += "\n" + spaces : null
i === 1 ? (i = 0) : i++;
spaces += " ";
n--
}
res = temp.split(" ").reverse().join(" ")
} else {
spaces += " "
let temp = ""
let i = 0;
while (n !== 0) {
temp += steps[i];
i === 0 ? (temp += "\n" + spaces) : null;
i === 1 ? (i = 0) : i++;
spaces += " ";
n++;
}
res = temp
}
return res
}

console.log(createLadder(-3))
console.log(createLadder(-7))
console.log(createLadder(10))
console.log(createLadder(18))

0 comments on commit 49ed33b

Please sign in to comment.