Sha256: de57b16483825d9032a9079976575b869bb4ce10ab1cbb7b52184dfb5bbe10d5

Contents?: true

Size: 1.36 KB

Versions: 5

Compression:

Stored size: 1.36 KB

Contents

class Array


	
    def fors
        sorted = [self[0]]
        for i in (1...self.size)
            act = self[i]
            for j in (0..sorted.size)
                if (j == sorted.size)
                    sorted.push(act)
                elsif (act.for_helper < sorted[j].for_helper)
                    sorted.insert(j, act)
                    break
                end
            end
        end
        return sorted
	end
	
    def eachs
        sorted = [self[0]]
        self.each_with_index do |x, pos_x|
            if (pos_x != 0)
                sorted.each_with_index do |y, pos_y|
                    if (pos_y == sorted.size-1)
                        if (x.each_helper < y.each_helper)
                            sorted.insert(pos_y, x)
                            break
                        else
                            sorted.push(x)
                            break
                        end
                    elsif (x.each_helper < y.each_helper)
                        sorted.insert(pos_y, x)
                        break
                    end
                end
            end
        end
        return sorted
	end
	
	def for_helper
        sum = 0
        for i in (0...self.size)
            sum += self[i].energy
        end
        return sum
	end

	def each_helper
        return self.collect{|food| food.energy;}.reduce(:+).round(2)
	end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
prct007-0.1.2 lib/prct06/array.rb
menu_juli-0.4.0 lib/prct06/array.rb
menu_juli-0.3.0 lib/prct06/array.rb
menu_juli-0.2.0 lib/prct06/array.rb
menu_juli-0.1.0 lib/prct06/array.rb