From c6bcb79feab57befdb901fc5aba5d2c396211472 Mon Sep 17 00:00:00 2001 From: Matthew Ellison Date: Thu, 28 Mar 2019 12:13:18 -0400 Subject: [PATCH] Fixed but where getProd would return 1 when the ary was empty --- Algorithms.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Algorithms.lua b/Algorithms.lua index 34cf9f2..298855e 100644 --- a/Algorithms.lua +++ b/Algorithms.lua @@ -233,6 +233,9 @@ function getSum(ary) end function getProd(ary) + if((ary == nil) or (#ary == 0)) then + return 0; + end local prod = 1; --Holds the product of all elements. Start at 1 because num*1 = num --Look through every element in the array and add the number to the running product for location = 1, #ary do