Хомогенизиране

Краен срок
19.10.2013 12:00

Срокът за предаване на решения е отминал

Дефинирайте метод homogenize(items), който приема списък, състоящ се от различни елементи и ги разделя типово, връщайки списък от хомогенни списъци.

Вътрешния ред на всеки подсписък трябва да запазва реда на срещане на елементите в подадения списък. Редът на самите подсписъци във върнатия списък не е от значение.

При подаден празен списък, методът връща празен списък.

Примери:

homogenize [1, :a, 2, :b, 3, :c]    # [[1, 2, 3], [:a, :b, :c]]
homogenize [:a, "Jimi", "Kurt", :b] # [[:a, :b], ["Jimi", "Kurt"]]

Решения

Петко Борджуков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Петко Борджуков
def homogenize(items)
items.group_by(&:class).values
end
...

Finished in 0.00443 seconds
3 examples, 0 failures
Димитър Керанов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Димитър Керанов
def homogenize(items)
items.group_by(&:class).values
end
...

Finished in 0.09895 seconds
3 examples, 0 failures
Радослав Даскалов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Радослав Даскалов
def homogenize(items)
items.group_by {|e| e.class}.values
end
...

Finished in 0.02483 seconds
3 examples, 0 failures
Илия Ватахов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Илия Ватахов
def homogenize(items)
grouped_items_by_type = Hash.new { |h, k| h[k] = [] }
items.each { |item| grouped_items_by_type[item.class] << item }
grouped_items_by_type.values
end
...

Finished in 0.00456 seconds
3 examples, 0 failures
Стефан Василев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Стефан Василев
def search_for_specific_type(array_to_search, type)
result_array = []
array_to_search.each { |i| result_array << i if i.class == type }
result_array
end
def type_exists?(array_to_search, type)
array_to_search.any? { |i| i == type }
end
def homogenize(item)
result_array, types_array = [], []
item.each do |i|
unless type_exists?(types_array, i.class)
result_array << search_for_specific_type(item, i.class)
types_array << i.class
end
end
result_array
end
...

Finished in 0.00533 seconds
3 examples, 0 failures
Георги Пурнаров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Пурнаров
def homogenize (items)
list=[]
item_list=[]
items.each { |element| item_list.push element}
while(not item_list.empty?)
current_list=[]
current_element=item_list[0]
i=0
while(i<item_list.size)
if current_element.class == item_list[i].class
current_list.push item_list.delete_at(i)
else i+=1
end
end
list.push current_list
end
return list
end
...

Finished in 0.00447 seconds
3 examples, 0 failures
Илия Тобов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Илия Тобов
def homogenize(items)
items.group_by { |element| element.class }.values
end
...

Finished in 0.00439 seconds
3 examples, 0 failures
Емануела Моллова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Емануела Моллова
def homogenize(items)
items.group_by(&:class).values
end
...

Finished in 0.00448 seconds
3 examples, 0 failures
Цветан Иванов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Иванов
def homogenize(elements)
elements.group_by { |element| element.class.to_s }.values
end
...

Finished in 0.00486 seconds
3 examples, 0 failures
Деян Хаджиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Деян Хаджиев
def homogenize(items)
items.map { |each_item| each_item.class } .uniq.inject([]) do |accumulator, object_type|
accumulator << items.select { |each_item| each_item.class == object_type }
end
end
...

Finished in 0.00452 seconds
3 examples, 0 failures
Диан Николов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Диан Николов
def isSameType?(element, array)
array[0].class == element.class
end
def homogenize(array)
arrayOfClasses = []
array.each do |element|
flag = false
arrayOfClasses.each do |typedArray|
if isSameType?(element, typedArray)
typedArray << element
flag = true
end
end
if false == flag then arrayOfClasses << [element] end
end
arrayOfClasses
end
...

Finished in 0.00444 seconds
3 examples, 0 failures
Красимира Божанова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Красимира Божанова
def homogenize(items)
items.group_by(&:class).values
end
...

Finished in 0.00444 seconds
3 examples, 0 failures
Методи Димитров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Методи Димитров
def homogenize(items)
items.each.group_by { |item| item.class }.values
end
...

Finished in 0.00438 seconds
3 examples, 0 failures
Александър Попов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Александър Попов
def homogenize(items)
homogenized = {}
items.each do |item|
homogenized[item.class] = [] unless homogenized[item.class]
homogenized[item.class] << item
end
homogenized.values
end
...

Finished in 0.00451 seconds
3 examples, 0 failures
Веселин Генадиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Веселин Генадиев
def homogenize(items)
type_values_hash = {}
items.each{|x| type_values_hash.has_key?(x.class) ?
type_values_hash[x.class] += [x] : type_values_hash[x.class] = [x] }
type_values_hash.values
end
...

Finished in 0.00558 seconds
3 examples, 0 failures
Александър Тахчиев
  • Некоректно
  • 1 успешни тест(а)
  • 2 неуспешни тест(а)
Александър Тахчиев
def sameclass? (type)
self.class == type.class
end
def homogenize(items)
answer = []
items.each do |i|
answer << same_class_elements = items.select{|x| x.sameclass?(i)}
items = items - same_class_elements
end
answer.select{|i| i != []}
end
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
Иван Проданов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Иван Проданов
def homogenize (items)
items.each_with_object({}){|item, hash| hash[item.class] = hash[item.class].to_a << item}.values
end
...

Finished in 0.0056 seconds
3 examples, 0 failures
Кристиян Азманов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиян Азманов
def homogenize(items)
result = {}
items.each do |curr_type|
result[curr_type.class] == nil ? result[curr_type.class] = [] << curr_type : result[curr_type.class]<<curr_type end
return result.values
end
...

Finished in 0.00452 seconds
3 examples, 0 failures
Христо Хърсев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Хърсев
def homogenize(items)
item_classes = {}
items.each do |item|
item_classes[item.class()] ||= []
item_classes[item.class()] << item
end
item_classes.values()
end
...

Finished in 0.00436 seconds
3 examples, 0 failures
Георги Ангелов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Ангелов
def homogenize(heterogeneous)
heterogeneous.group_by(&:class).values
end
...

Finished in 0.00443 seconds
3 examples, 0 failures
Мария Митева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Митева
def homogenize(items)
items.group_by { |item| item.class }.values
end
...

Finished in 0.00503 seconds
3 examples, 0 failures
Георги Гърдев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Гърдев
def homogenize(items)
items.group_by(&:class).values
end
...

Finished in 0.00448 seconds
3 examples, 0 failures
Николай Генов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Николай Генов
def homogenize(items)
items.group_by(&:class).values
end
...

Finished in 0.00437 seconds
3 examples, 0 failures
Владимир Кузмов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Владимир Кузмов
def homogenize list
list.group_by(&:class).inject(:+).select { |item| item.kind_of?(Array) }
end
.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
Ясен Трифонов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Ясен Трифонов
#!/usr/local/bin/ruby -w
def homogenize(items)
items.group_by(&:class).values
end
...

Finished in 0.00573 seconds
3 examples, 0 failures
Антонио Николов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Антонио Николов
def homogenize(items)
types_content, separeted_types, one_type_holder = [], [], []
(items).each do |element|
if (types_content).none? { |checked_type| checked_type == element.class }
(items).each { |element_with_that_type| one_type_holder << element_with_that_type if element.class == element_with_that_type.class }
types_content << element.class
separeted_types << one_type_holder
one_type_holder = []
end
end
separeted_types
end
...

Finished in 0.00449 seconds
3 examples, 0 failures
Росен Рачев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Росен Рачев
def homogenize(items = [])
items.group_by { |item| item.class }.values
end
...

Finished in 0.00566 seconds
3 examples, 0 failures
Ангел Венчев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Венчев
def homogenize(items)
items.group_by(&:class).values
end
...

Finished in 0.0317 seconds
3 examples, 0 failures
Кристиан Ташков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиан Ташков
def homogenize(items)
items.group_by { |element| element.class }.values
end
...

Finished in 0.00485 seconds
3 examples, 0 failures
Никола Ненков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Никола Ненков
def homogenize(items)
items.group_by(&:class).values
end
...

Finished in 0.00465 seconds
3 examples, 0 failures
Аделина Рудова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Аделина Рудова
def homogenize(items)
array_of_homogenized_arrays = []
type_arrays = make_hash_of_type_arrays items
type_arrays.each_value { |x| array_of_homogenized_arrays << x}
return array_of_homogenized_arrays
end
def make_subarray(heterogeneous_array, type)
homogenized_subarray = []
heterogeneous_array.each { |x| homogenized_subarray << x if x.class == type}
return homogenized_subarray
end
def make_hash_of_type_arrays(heterogeneous_array)
type_arrays = {}
heterogeneous_array.each { |x| type_arrays[x.class] = make_subarray(heterogeneous_array, x.class) }
return type_arrays
end
...

Finished in 0.00464 seconds
3 examples, 0 failures
Марио Даскалов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Марио Даскалов
def homogenize(items)
homogenized_hash = items.reduce({}) do |memo, object|
if memo.has_key?(object.class)
memo[object.class] << object
else
memo[object.class] = [object]
end
memo
end
homogenized_hash.values
end
...

Finished in 0.00453 seconds
3 examples, 0 failures
Владимир Конушлиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Владимир Конушлиев
def homogenize(items)
items.group_by(&:class).values
end
...

Finished in 0.0044 seconds
3 examples, 0 failures
Милен Мавров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Милен Мавров
def homogenize(items)
homogenized_hash = {}
items.each do |elem|
if homogenized_hash.key?(elem.class)
homogenized_hash[elem.class] << elem
else
homogenized_hash[elem.class] = [elem]
end
end
homogenized_hash.values
end
...

Finished in 0.00452 seconds
3 examples, 0 failures
Станимир Килявков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Станимир Килявков
def homogenize(items)
items.group_by{|i| i.class }.values
end
...

Finished in 0.00436 seconds
3 examples, 0 failures
Петя Делчева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Петя Делчева
def homogenize(input)
input.group_by{|i| i.class }.values
end
...

Finished in 0.00437 seconds
3 examples, 0 failures
Сияна Славова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Сияна Славова
def homogenize(items)
homogenized_array = []
items.each do |element|
array_of_frequence = items.find_all { |current_element| current_element.class == element.class }
homogenized_array << array_of_frequence unless homogenized_array.include? array_of_frequence
end
homogenized_array
end
...

Finished in 0.00463 seconds
3 examples, 0 failures
Венцислав Велков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Венцислав Велков
def homogenize(arr)
final_array = []
arrcpy = Array.new(arr)
while !(arrcpy.empty?)
final_array << arrcpy.select { |i| i.class == arrcpy[0].class }
arrcpy.delete_if { |i| i.class == final_array.last.last.class }
end
final_array
end
...

Finished in 0.00457 seconds
3 examples, 0 failures
Петър Мазълов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Петър Мазълов
def homogenize(items)
types = items.map { |item| item.class }.uniq
types.map do |type|
items.select { |item| item.class == type }
end
end
...

Finished in 0.00458 seconds
3 examples, 0 failures
Георги Шопов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Георги Шопов
def homogenize(items)
class_index_hash = {}
items.each_with_object([]) do |item, list|
item_class = item.class
if class_index_hash.include? item_class
list[class_index_hash[item_class]] << item
else
class_index_hash[item_class] = list.length
list[class_index_hash[item_class]] = [item]
end
end
end
...

Finished in 0.00439 seconds
3 examples, 0 failures
Сашо Михайлов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Сашо Михайлов
def homogenize(items)
def homogenize_help(items,items_iter)
result_help,result_help_counter = [],0
result_help << items[0]
items.delete_at(0)
while items_iter<items.size
if result_help[result_help_counter]<=>(items[items_iter])
result_help << items[items_iter]
result_help_counter+=1
items.delete_at(items_iter)
items_iter-=1
else
items_iter+=1
end
end
return result_help
end
result,result_counter = [],0
while items.size>0
result[result_counter]=homogenize_help(items,0)
result_counter+=1
end
return result
end
p homogenize [:a,"Jimi","Kurt",:b,"gfg",1]
[[: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
Цветан Коев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Цветан Коев
def homogenize(items)
items.group_by { |x| x.class }.values
end
...

Finished in 0.00433 seconds
3 examples, 0 failures
Слав Керемидчиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Слав Керемидчиев
def homogenize(items)
output_array = []
types_items = items.map { |element| element.class }.uniq
types_items.each do |i|
output_array.push(items.select { |j| j.instance_of? i })
end
output_array
end
...

Finished in 0.00453 seconds
3 examples, 0 failures
Томислав Иванов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Томислав Иванов
def homogenize(items)
homogenize_groups = {}
items.each do |element|
if homogenize_groups.has_key?(element.class)
homogenize_groups[element.class].push(element)
else
homogenize_groups[element.class] = [element]
end
end
homogenize_groups.values.to_a
end
...

Finished in 0.00452 seconds
3 examples, 0 failures
Любомир Георгиев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Любомир Георгиев
def homogenize(items)
hash_typo = {}
items.each do |item|
hash_typo[item.class()] = [] if not hash_typo[item.class()].is_a? Enumerable
hash_typo[item.class()].push(item)
end
return_array = []
hash_typo.each {|key, value| return_array.push(value) }
return_array
end
...

Finished in 0.00458 seconds
3 examples, 0 failures
Илиян Танев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Илиян Танев
def homogenize(list)
hash = {}
list.each { |item| hash.has_key?(item.class) ? hash[item.class] << item : hash[item.class] = [] << item }
hash.values
end
...

Finished in 0.00442 seconds
3 examples, 0 failures
Кристиян Кисимов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиян Кисимов
def homogenize(items)
result_array = []
items.each do |element|
result_array << items.find_all { |i| i.class.equal? element.class }
end
result_array.uniq { |i| i.first }
end
...

Finished in 0.00458 seconds
3 examples, 0 failures
Моника Димитрова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Моника Димитрова
def homogenize(items)
items.group_by { |object| object.class }.values
end
...

Finished in 0.00458 seconds
3 examples, 0 failures
Христо Аврамов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Христо Аврамов
def homogenize(items)
homogenHash = {}
homogenArray=[]
items.each do |item|
if homogenHash[item.class] then
homogenHash[item.class].push item
else
homogenHash[item.class] = []
homogenHash[item.class].push item
end
end
homogenHash.each_value {|list| homogenArray.push list }
homogenArray
end
...

Finished in 0.00449 seconds
3 examples, 0 failures
Мария Терзиева
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Мария Терзиева
def homogenize(items)
items.group_by { |item| item.class }.values
end
...

Finished in 0.00432 seconds
3 examples, 0 failures
Наталия Пацовска
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Наталия Пацовска
def homogenize(items)
items.group_by { |item| item.class }.values
end
...

Finished in 0.00434 seconds
3 examples, 0 failures
Ангел Цанев
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Ангел Цанев
def homogenize(items)
items.group_by { |a| a.class } .values
end
...

Finished in 0.00429 seconds
3 examples, 0 failures
Радина Петкова
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Радина Петкова
def homogenize items
return [] if items == []
vals_types = []
homogenized_ls = []
0.upto(items.size - 1) do |x| vals_types.push items[x].class end
unique_types_ls = vals_types.uniq
0.upto(unique_types_ls.size - 1) do |x|
homogenized_ls.push items.select{ |i| i.class == unique_types_ls[x] } end
homogenized_ls
end
...

Finished in 0.00461 seconds
3 examples, 0 failures
Давид Петров
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Давид Петров
def homogenize(items)
types={}
items.each {|x| types[x.class]=[] }
items.each {|x| types[x.class].push(x) }
group=[]
types.each_pair{ |k,v| group.push(v)}
group
end
...

Finished in 0.00448 seconds
3 examples, 0 failures
Моника Илиева
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Моника Илиева
def homogenize(items)
arr_with_integers = []
arr_with_rational = []
arr_with_float = []
arr_with_strings = []
arr_with_symbols = []
arr_with_hash = []
arr_with_array = []
arr_nil_class = []
arr_with_classes = []
arr_true_class = []
arr_false_class = []
return items if items.empty?
items.each do |elements|
arr_with_integers << elements if elements.is_a? Integer
arr_with_rational << elements if elements.is_a? Rational
arr_with_float << elements if elements.is_a? Float
arr_with_strings << elements if elements.is_a? String
arr_with_symbols << elements if elements.is_a? Symbol
arr_with_hash << elements if elements.is_a? Hash
arr_with_array << elements if elements.is_a? Array
arr_nil_class << elements if elements.is_a? NilClass
arr_with_classes << elements if elements.is_a? Class
arr_false_class << elements if elements.is_a? FalseClass
arr_true_class << elements if elements.is_a? TrueClass
end
arr = []
arr << arr_with_integers << arr_with_symbols << arr_with_hash
arr << arr_with_float << arr_with_rational << arr_with_strings
arr << arr_with_array << arr_nil_class << arr_with_classes
arr << arr_false_class << arr_true_class
arr.delete_if { |elements| elements.empty? }
end
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
Кристиан Цветков
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Кристиан Цветков
def homogenize(items)
return items if items.empty?
result = Hash.new{|h, k| h[k] = []}
items.each do |item|
result[item.class] << item
end
result.values
end
...

Finished in 0.00442 seconds
3 examples, 0 failures
Калоян Калудов
  • Коректно
  • 3 успешни тест(а)
  • 0 неуспешни тест(а)
Калоян Калудов
def homogenize(items)
homogenized = []
current_type = ->(element) { element.class == items.first.class }
until items.empty?
homogenized << items.select(&current_type)
items = items.reject(&current_type)
end
homogenized
end
...

Finished in 0.00549 seconds
3 examples, 0 failures
Явор Михайлов
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Явор Михайлов
# flatten for multidimensional arrays
def homogenize(array)
array.flatten.group_by { |element| element.class }.values
end
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
Лилия Любенова
  • Некоректно
  • 2 успешни тест(а)
  • 1 неуспешни тест(а)
Лилия Любенова
def homogenize(items)
input = Array.new(items)
homogenized = []
while input.length > 0
same_elements = []
same_elements.push(input.shift)
same_elements.push (input.select {|element| element.class == same_elements[0].class})
same_elements.flatten! unless same_elements[0].class.name == "Array"
input.select! {|element| not element.class == same_elements[0].class}
homogenized.push same_elements
end
return homogenized
end
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