Last active
December 1, 2017 07:00
-
-
Save hyjk2000/d1679bca25cf40554e408a832f7c4737 to your computer and use it in GitHub Desktop.
Recursive Letters with Indentations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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