Question I have a custom divide and conquer array sorter that I would like to use. This all works well until I try to use it on an array in my controller I get this message.. NoMethodError (undefined method `<=' for #): Any help would be greatly appreciated thank you!
here is my Entry model with the mergesort method I am calling in my controller.
def self.mergesort(container)
return container if (container.size <= 1)
mid = container.size / 2
left = container[0...mid]
right = container[mid...container.size]
merge(mergesort(left), mergesort(right))
end
def self.merge(left, right)
sorted = []
until left.empty? or right.empty?
(left.first <= right.first) ? sorted << left.shift : sorted << right.shift
end
sorted + left + right
end
end end
Here is my Entry controller where I am trying to call it.
def pending_sort
@ent_sort = Entry.where("section = ? and approve_disapprove = ?", @mgr_section, '3')
@ent = Entry.mergesort(@ent_sort)
end
Aucun commentaire:
Enregistrer un commentaire