diff --git a/__tests__/Functions__Test.re b/__tests__/Functions__Test.re index a0500e00..d5cc0d03 100644 --- a/__tests__/Functions__Test.re +++ b/__tests__/Functions__Test.re @@ -60,4 +60,13 @@ describe("Functions", () => { expect(Functions.min([|(-1.), (-2.), 0., 20., (-2.2)|])) |> toEqual(-2.2) }); + test("max#1", () => { + expect(Functions.max([|1., 2., 3.|])) |> toEqual(3.) + }); + test("max#2", () => { + expect(Functions.max([|(-1.), (-2.), 0., 20.|])) |> toEqual(20.) + }); + test("max#3", () => { + expect(Functions.max([|(-1.), (-2.), 0., (-2.2)|])) |> toEqual(0.) + }); }); diff --git a/src/utility/lib/Functions.re b/src/utility/lib/Functions.re index 0f310966..4600f237 100644 --- a/src/utility/lib/Functions.re +++ b/src/utility/lib/Functions.re @@ -12,7 +12,7 @@ let interpolate = let sum = Belt.Array.reduce(_, 0., (i, j) => i +. j); let mean = a => sum(a) /. (Array.length(a) |> float_of_int); 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 max = a => Belt.Array.reduce(a, a[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); let range = (min: float, max: float, n: int): array(float) => {