Value of the last element of a list

前端 未结 10 975
小蘑菇
小蘑菇 2020-12-18 18:55

how to get the value of the last element of a List? I\'ve noted that List.hd (or .Head) return an item, while List.tl (or .Tail) returns a List.

Is rev the List and

10条回答
  •  我在风中等你
    2020-12-18 19:21

    Below code worked fine with me, I've an array of integers, want to start from the 5th item, then take it minus the item number

    Sum of [Array(xi) - Array(xi-5)] where i start at 5
    

    The code used is:

    series |> Array.windowed 5
           |> Array.fold (fun s x -> 
                                (x |> Array.rev |> Array.head) -  (x |> Array.head) + s) 0
           |> float
    

提交回复
热议问题