diff --git a/__tests__/Functions__Test.re b/__tests__/Functions__Test.re index 80c42fc7..a0500e00 100644 --- a/__tests__/Functions__Test.re +++ b/__tests__/Functions__Test.re @@ -50,4 +50,14 @@ describe("Functions", () => { test("mean#3", () => { expect(Functions.mean([|1., 2., 3., (-2.), (-10.)|])) |> toEqual(-1.2) }); + test("min#1", () => { + expect(Functions.min([|1., 2., 3.|])) |> toEqual(1.) + }); + test("min#2", () => { + expect(Functions.min([|(-1.), (-2.), 0., 20.|])) |> toEqual(-2.) + }); + test("min#3", () => { + expect(Functions.min([|(-1.), (-2.), 0., 20., (-2.2)|])) + |> toEqual(-2.2) + }); }); diff --git a/src/utility/lib/Functions.re b/src/utility/lib/Functions.re index a2e4ba66..0f310966 100644 --- a/src/utility/lib/Functions.re +++ b/src/utility/lib/Functions.re @@ -11,7 +11,7 @@ let interpolate = // @todo: To test! let sum = Belt.Array.reduce(_, 0., (i, j) => i +. j); let mean = a => sum(a) /. (Array.length(a) |> float_of_int); -let min = Belt.Array.reduce(_, 0., (i, j) => i < j ? i : j); +let min = a => Belt.Array.reduce(a, a[0], (i, j) => i < j ? i : j); let max = Belt.Array.reduce(_, 0., (i, j) => i > j ? i : j); let up = (a, b) => Array.make(b - a, a) |> Array.mapi((i, c) => c + i); let down = (a, b) => Array.make(a - b, a) |> Array.mapi((i, c) => c - i);