Skip to content

Instantly share code, notes, and snippets.

@hyjk2000
Last active December 1, 2017 07:00
Show Gist options
  • Select an option

  • Save hyjk2000/d1679bca25cf40554e408a832f7c4737 to your computer and use it in GitHub Desktop.

Select an option

Save hyjk2000/d1679bca25cf40554e408a832f7c4737 to your computer and use it in GitHub Desktop.
Recursive Letters with Indentations
def recursive_letters(letters, depth = 0)
character = letters.shift
indentation = ' ' * depth
puts "#{indentation}<#{character}>"
recursive_letters(letters, depth + 1) unless letters.empty?
puts "#{indentation}</#{character}>"
end
require 'rspec'
require './recursive_letters'
describe :recursive_letters do
subject { recursive_letters %w[a b c d e f] }
expected_output = <<~OUTPUT
<a>
<b>
<c>
<d>
<e>
<f>
</f>
</e>
</d>
</c>
</b>
</a>
OUTPUT
it 'outputs the expected output' do
expect { subject }.to output(expected_output).to_stdout
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment