-
Notifications
You must be signed in to change notification settings - Fork 0
/
maxr.fsx
33 lines (26 loc) · 940 Bytes
/
maxr.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
(*
Write funcion maxR which returns maximum value of a given List Try no to cheat and provide recursive solution.
taken from https://www.codewars.com/kata/57a8873cbb99449e300000ba/train/fsharp
*)
let maxR list =
let rec maxl mx ns =
match ns with
|[] -> mx
|h::t -> match h with
|_ when h > mx -> maxl h t
|_ -> maxl mx t
match list with
|[] -> None
|_ -> Some(maxl list.[0] list)
// let rec max mx (ns: 'a seq) =
// match ns with
// |_ when ns |> Seq.isEmpty -> mx
// |_ -> match ns |> Seq.head with
// |h when h > mx -> max h (ns |> Seq.skip 1)
// |_ -> max mx (ns |> Seq.skip 1)
// match list with
// |_ when list |> Seq.isEmpty -> None
// |_ -> Some(max (list |> Seq.head) list)
// let m0:int option = maxR []
let m1 = maxR [1;2;51;8;3;9]
// let m2 = maxR [|4;5;5;6;|]