From 6e70556e397f58783208e20cca18e0b8ed6bbdf2 Mon Sep 17 00:00:00 2001 From: Vitor Oliveira Date: Wed, 28 Apr 2021 18:33:20 -0700 Subject: [PATCH] use elsif instead --- maths/factorial_non_recursive_non_iterative.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/maths/factorial_non_recursive_non_iterative.rb b/maths/factorial_non_recursive_non_iterative.rb index f19f4ad..f992a92 100644 --- a/maths/factorial_non_recursive_non_iterative.rb +++ b/maths/factorial_non_recursive_non_iterative.rb @@ -9,12 +9,11 @@ def factorial(number) if number < 0 "Please check your input number! The given number is a negative number." + elsif number == 0 + "The factorial of #{number} is 1." else - if number == 0 - "The factorial of #{number} is 1." - else - "The factorial of #{number} is #{(1..number).inject(:*)}." - end + result = (1..number).inject(:*) + "The factorial of #{number} is #{result}." end rescue "Error: Please provide integer only!"