diff options
| author | mo <mokha@cisco.com> | 2017-08-09 15:28:45 -0600 |
|---|---|---|
| committer | mo <mokha@cisco.com> | 2017-08-09 15:28:45 -0600 |
| commit | 2528c1dcc3beef34f961427701e5a32e28822e9e (patch) | |
| tree | 42e6aadeab253be4571e069abb78099e11a8ec92 | |
| parent | efb899eaa9f14a275471bfdf975e4a776f65ad62 (diff) | |
reduce params to search method.
| -rw-r--r-- | spec/binary_trees/restore_binary_tree_spec.rb | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/spec/binary_trees/restore_binary_tree_spec.rb b/spec/binary_trees/restore_binary_tree_spec.rb index 7003464..2f42ca6 100644 --- a/spec/binary_trees/restore_binary_tree_spec.rb +++ b/spec/binary_trees/restore_binary_tree_spec.rb @@ -84,8 +84,8 @@ DOC describe "#restore_binary_tree" do $preorder_index = 0 - def search(items, start, end_range, target) - items[start..end_range].find_index { |x| x == target } + start + def search(items, target) + items.find_index { |x| x == target } end def build_tree(inorder, preorder, start_index, end_index) @@ -97,7 +97,7 @@ describe "#restore_binary_tree" do return node if start_index == end_index - index = search(inorder, start_index, end_index, value) + index = search(inorder[start_index..end_index], value) + start_index node.left = build_tree(inorder, preorder, start_index, index - 1) node.right = build_tree(inorder, preorder, index + 1, end_index) node |
