diff options
| author | mokha <mokha@cisco.com> | 2017-09-18 10:21:05 -0600 |
|---|---|---|
| committer | mokha <mokha@cisco.com> | 2017-09-18 10:21:05 -0600 |
| commit | 0aafd6fc6df1ac91d5bcc8de12ee22cf4cd4c206 (patch) | |
| tree | 95d9a0de6ebcba94f6a46c5ee62c976c47751e15 | |
| parent | edc952f117c5358a53f7c49c6464c4d5ff78d67f (diff) | |
solve simplify path.
| -rw-r--r-- | spec/heaps_stacks_queues/simplify_path_spec.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/spec/heaps_stacks_queues/simplify_path_spec.rb b/spec/heaps_stacks_queues/simplify_path_spec.rb index 7aaed69..af40158 100644 --- a/spec/heaps_stacks_queues/simplify_path_spec.rb +++ b/spec/heaps_stacks_queues/simplify_path_spec.rb @@ -35,7 +35,18 @@ DOC describe "simplify_path" do def simplify_path(path) - path + result = [] + path.split('/').each do |part| + case part + when '.' + when '..' + result.pop + when '' + else + result.push(part) + end + end + "/" + result.join('/') end [ |
