Skip to content

Commit

Permalink
Reto mouredev#16 - ruby
Browse files Browse the repository at this point in the history
  • Loading branch information
test0n3 committed Apr 18, 2023
1 parent 3a432c6 commit 2293035
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions Retos/Reto #16 - LA ESCALERA [Media]/ruby/test0n3.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

def stairs_generator(input)
stairs = downward_stairs(input.abs)

stairs = upward_stairs(stairs) if input.positive?

stairs.join("\n")
end

def downward_stairs(input)
stairs = ['_']
stairs[0] += '_' if input.zero?

stair = 1
while stair <= input
stairs[stair] = "#{' ' * stairs[stair - 1].length}|_"
stair += 1
end
stairs
end

def upward_stairs(negative_stairs)
max_string_length = negative_stairs.last.length
negative_stairs.map do |item|
item += ' ' * (max_string_length - item.length)
item.reverse
end
end

# puts stairs_generator(-5)
# puts stairs_generator(4)

0 comments on commit 2293035

Please sign in to comment.