diff --git a/Algorithms.lua b/Algorithms.lua index b219ba9..833ee8a 100644 --- a/Algorithms.lua +++ b/Algorithms.lua @@ -175,3 +175,23 @@ function getDivisors(goalNumber) --Return the list return divisors; end + +function getSum(ary) + sum = 0; --Holds the sum of all elements. Start at 0 because num+1 = num + --Look through every element in the array and add the number to the running sum + for location = 1, #ary do + sum = sum + ary[location]; + end + --Return the sum of all elements + return sum; +end + +function getProd(ary) + 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 + prod = prod * ary[location]; + end + --Return the product of all elements + return prod; +end