Commits

Bożydar Sobczak committed be2a437

More functional

Comments (0)

Files changed (1)

 end
 
 def min(*list)
-  acc = nil
-  list.each do |item|
-    acc = item if acc.nil? || item < acc 
+  list.inject(nil) do |acc, item|
+    if acc.nil? || item < acc 
+      item
+    else
+      acc
+    end
   end
-  acc
 end
 
 def max(*list)
-  acc = nil
-  list.each do |item|
-    acc = item if acc.nil? || item > acc 
+  list.inject(nil) do |acc, item|
+    if acc.nil? || item > acc 
+      item
+    else
+      acc
+    end
   end
-  acc
 end
 
 def factorial_classic(arg)
   elsif arg == 0
     1
   else
-    acc = 1
-    (1..arg).each { |item| 
-      acc *= item
-    }
-    acc
+    (1..arg).inject(1) do |acc, item| 
+      acc * item
+    end
   end
 end
 
 end
 
 def tree(arg)
-  (1..arg).each { |item|
+  (1..arg).each do |item|
     puts " " * (arg - item) + ("##" * item)
-  }
+  end
   puts " " * (arg - 1) + "##"
 end