- Коректно
- 3 успешни тест(а)
- 0 неуспешни тест(а)
def homogenize(items)
items.group_by(&:class).values
end
... Finished in 0.00443 seconds 3 examples, 0 failures
Срокът за предаване на решения е отминал
Дефинирайте метод homogenize(items)
, който приема списък, състоящ се от
различни елементи и ги разделя типово, връщайки списък от хомогенни списъци.
Вътрешния ред на всеки подсписък трябва да запазва реда на срещане на елементите в подадения списък. Редът на самите подсписъци във върнатия списък не е от значение.
При подаден празен списък, методът връща празен списък.
Примери:
homogenize [1, :a, 2, :b, 3, :c] # [[1, 2, 3], [:a, :b, :c]]
homogenize [:a, "Jimi", "Kurt", :b] # [[:a, :b], ["Jimi", "Kurt"]]
... Finished in 0.00443 seconds 3 examples, 0 failures
... Finished in 0.09895 seconds 3 examples, 0 failures
... Finished in 0.02483 seconds 3 examples, 0 failures
... Finished in 0.00456 seconds 3 examples, 0 failures
... Finished in 0.00533 seconds 3 examples, 0 failures
... Finished in 0.00447 seconds 3 examples, 0 failures
... Finished in 0.00439 seconds 3 examples, 0 failures
... Finished in 0.00448 seconds 3 examples, 0 failures
... Finished in 0.00486 seconds 3 examples, 0 failures
... Finished in 0.00452 seconds 3 examples, 0 failures
... Finished in 0.00444 seconds 3 examples, 0 failures
... Finished in 0.00444 seconds 3 examples, 0 failures
... Finished in 0.00438 seconds 3 examples, 0 failures
... Finished in 0.00451 seconds 3 examples, 0 failures
... Finished in 0.00558 seconds 3 examples, 0 failures
F.F Failures: 1) homogenize returns array of homogeneous arrays Failure/Error: homogenize([1, :a, 2, :b, 3, :c, 1/2r]).should =~ [[1/2r], NoMethodError: private method `sameclass?' called for 1:Fixnum # /tmp/d20131021-16294-srbsjd/solution.rb:8:in `block (2 levels) in homogenize' # /tmp/d20131021-16294-srbsjd/solution.rb:8:in `select' # /tmp/d20131021-16294-srbsjd/solution.rb:8:in `block in homogenize' # /tmp/d20131021-16294-srbsjd/solution.rb:7:in `each' # /tmp/d20131021-16294-srbsjd/solution.rb:7:in `homogenize' # /tmp/d20131021-16294-srbsjd/spec.rb:6:in `block (2 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' 2) homogenize preserves the order Failure/Error: homogenize([1, :a, 2, :b, 3, :c]).should =~ [[1, 2, 3], [:a, :b, :c]] NoMethodError: private method `sameclass?' called for 1:Fixnum # /tmp/d20131021-16294-srbsjd/solution.rb:8:in `block (2 levels) in homogenize' # /tmp/d20131021-16294-srbsjd/solution.rb:8:in `select' # /tmp/d20131021-16294-srbsjd/solution.rb:8:in `block in homogenize' # /tmp/d20131021-16294-srbsjd/solution.rb:7:in `each' # /tmp/d20131021-16294-srbsjd/solution.rb:7:in `homogenize' # /tmp/d20131021-16294-srbsjd/spec.rb:24:in `block (2 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00466 seconds 3 examples, 2 failures Failed examples: rspec /tmp/d20131021-16294-srbsjd/spec.rb:2 # homogenize returns array of homogeneous arrays rspec /tmp/d20131021-16294-srbsjd/spec.rb:23 # homogenize preserves the order
... Finished in 0.0056 seconds 3 examples, 0 failures
... Finished in 0.00452 seconds 3 examples, 0 failures
... Finished in 0.00436 seconds 3 examples, 0 failures
... Finished in 0.00443 seconds 3 examples, 0 failures
... Finished in 0.00503 seconds 3 examples, 0 failures
... Finished in 0.00448 seconds 3 examples, 0 failures
... Finished in 0.00437 seconds 3 examples, 0 failures
.F. Failures: 1) homogenize returns empty array when empty array given Failure/Error: homogenize([]).should eq [] NoMethodError: private method `select' called for nil:NilClass # /tmp/d20131021-16294-h4wn8b/solution.rb:2:in `homogenize' # /tmp/d20131021-16294-h4wn8b/spec.rb:20:in `block (2 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00352 seconds 3 examples, 1 failure Failed examples: rspec /tmp/d20131021-16294-h4wn8b/spec.rb:19 # homogenize returns empty array when empty array given
... Finished in 0.00573 seconds 3 examples, 0 failures
... Finished in 0.00449 seconds 3 examples, 0 failures
... Finished in 0.00566 seconds 3 examples, 0 failures
... Finished in 0.0317 seconds 3 examples, 0 failures
... Finished in 0.00485 seconds 3 examples, 0 failures
... Finished in 0.00465 seconds 3 examples, 0 failures
... Finished in 0.00464 seconds 3 examples, 0 failures
... Finished in 0.00453 seconds 3 examples, 0 failures
... Finished in 0.0044 seconds 3 examples, 0 failures
... Finished in 0.00452 seconds 3 examples, 0 failures
... Finished in 0.00436 seconds 3 examples, 0 failures
... Finished in 0.00437 seconds 3 examples, 0 failures
... Finished in 0.00463 seconds 3 examples, 0 failures
... Finished in 0.00457 seconds 3 examples, 0 failures
... Finished in 0.00458 seconds 3 examples, 0 failures
... Finished in 0.00439 seconds 3 examples, 0 failures
[[:a, :b], ["Jimi", "Kurt", "gfg"], [1]] F.. Failures: 1) homogenize returns array of homogeneous arrays Failure/Error: [:a, :b, :c]] expected collection contained: [[(1/2)], [1, 2, 3], [:a, :b, :c]] actual collection contained: [[1, 2, 3, (1/2)], [:a, :b, :c]] the missing elements were: [[(1/2)], [1, 2, 3]] the extra elements were: [[1, 2, 3, (1/2)]] # /tmp/d20131021-16294-1e0lg7n/spec.rb:8:in `block (2 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00478 seconds 3 examples, 1 failure Failed examples: rspec /tmp/d20131021-16294-1e0lg7n/spec.rb:2 # homogenize returns array of homogeneous arrays
... Finished in 0.00433 seconds 3 examples, 0 failures
... Finished in 0.00453 seconds 3 examples, 0 failures
... Finished in 0.00452 seconds 3 examples, 0 failures
... Finished in 0.00458 seconds 3 examples, 0 failures
... Finished in 0.00442 seconds 3 examples, 0 failures
... Finished in 0.00458 seconds 3 examples, 0 failures
... Finished in 0.00458 seconds 3 examples, 0 failures
... Finished in 0.00449 seconds 3 examples, 0 failures
... Finished in 0.00432 seconds 3 examples, 0 failures
... Finished in 0.00434 seconds 3 examples, 0 failures
... Finished in 0.00429 seconds 3 examples, 0 failures
... Finished in 0.00461 seconds 3 examples, 0 failures
... Finished in 0.00448 seconds 3 examples, 0 failures
F.. Failures: 1) homogenize returns array of homogeneous arrays Failure/Error: [anonymous_nil]] expected collection contained: [[5, 6], [:a, :b], [[1, 2], [3, 4]], [#<Proc:0xba72b7c0@/tmp/d20131021-16294-1a7clgg/spec.rb:3 (lambda)>]] actual collection contained: [[5, 6], [:a, :b], [[1, 2], [3, 4]]] the missing elements were: [[#<Proc:0xba72b7c0@/tmp/d20131021-16294-1a7clgg/spec.rb:3 (lambda)>]] # /tmp/d20131021-16294-1a7clgg/spec.rb:16:in `block (2 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00491 seconds 3 examples, 1 failure Failed examples: rspec /tmp/d20131021-16294-1a7clgg/spec.rb:2 # homogenize returns array of homogeneous arrays
... Finished in 0.00442 seconds 3 examples, 0 failures
... Finished in 0.00549 seconds 3 examples, 0 failures
F.. Failures: 1) homogenize returns array of homogeneous arrays Failure/Error: [anonymous_nil]] expected collection contained: [[5, 6], [:a, :b], [[1, 2], [3, 4]], [#<Proc:0xb8d9d13c@/tmp/d20131021-16294-ebtr4n/spec.rb:3 (lambda)>]] actual collection contained: [[1, 2, 3, 4, 5, 6], [:a, :b], [#<Proc:0xb8d9d13c@/tmp/d20131021-16294-ebtr4n/spec.rb:3 (lambda)>]] the missing elements were: [[5, 6], [[1, 2], [3, 4]]] the extra elements were: [[1, 2, 3, 4, 5, 6]] # /tmp/d20131021-16294-ebtr4n/spec.rb:16:in `block (2 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.00617 seconds 3 examples, 1 failure Failed examples: rspec /tmp/d20131021-16294-ebtr4n/spec.rb:2 # homogenize returns array of homogeneous arrays
F.. Failures: 1) homogenize returns array of homogeneous arrays Failure/Error: [anonymous_nil]] expected collection contained: [[5, 6], [:a, :b], [[1, 2], [3, 4]], [#<Proc:0xb931c784@/tmp/d20131021-16294-em16ta/spec.rb:3 (lambda)>]] actual collection contained: [[[1, 2], [[3, 4]]], [:a, :b], [5, 6], [#<Proc:0xb931c784@/tmp/d20131021-16294-em16ta/spec.rb:3 (lambda)>]] the missing elements were: [[[1, 2], [3, 4]]] the extra elements were: [[[1, 2], [[3, 4]]]] # /tmp/d20131021-16294-em16ta/spec.rb:16:in `block (2 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>' # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>' Finished in 0.0053 seconds 3 examples, 1 failure Failed examples: rspec /tmp/d20131021-16294-em16ta/spec.rb:2 # homogenize returns array of homogeneous arrays