Skip to content

Recursion Practices with TDD (Test Driven Approach). Feel free to grab the test (rspec) files for your own practices.

Notifications You must be signed in to change notification settings

tedcheng/recursion_with_tdd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 

Repository files navigation

#Recursion Practices with TDD Including common recursion problems (implementation in Ruby):

  1. range
range(5, 10) 
#=> [6, 7, 8, 9]
  1. sum
[1, 2, 3].sum
#=> 6
  1. exponent
exp(2, 9)
#=> 512
exp(2, 7)
#=> 128
  1. Deep dup that handles arrays inside an array
test_arr = [[0, 1], [2, 3]]
test_arr.deep_dup
#=> [[0, 1], [2, 3]]
test_arr.object_id == test_arr.deep_dup.object_id
#=> false
  1. Fibonacci Sequence
fibs(6)
#=> [0, 1, 1, 2, 3, 5]
  1. Make Change
make_change(14)
#=> [10, 1, 1, 1, 1]
  1. Binary Search
bsearch([0, 1, 2, 3, 4, 5], 3)
#=> 3
bsearch([0, 1, 2, 3, 4, 5], 0)
#=> 0
bsearch([0, 1, 2, 3, 4, 5], 5)
#=> 5
bsearch([0, 1, 2, 3, 4, 5], 6)
#=> nil
  1. Merge Sort
merge_sort([2, 3, 1, 5, 2, 8, 9])
#=> [1, 2, 2, 3, 5, 8, 9]
# merge_sort runs in O (n log n) time
  1. Subsets
subsets([1, 2, 3])
#=> [[], [1], [2], [1, 2], [3], [1, 3], [2, 3], [1, 2, 3]]

About

Recursion Practices with TDD (Test Driven Approach). Feel free to grab the test (rspec) files for your own practices.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages