Split list into two equal lists in F#

后端 未结 7 417
遇见更好的自我
遇见更好的自我 2021-01-12 18:21

I\'m really new to F#, and I need a bit of help with an F# problem.

I need to implement a cut function that splits a list in half so that the output would be...

7条回答
  •  有刺的猬
    2021-01-12 19:01

    check this one out:

    let gencut s xs =  
        ([for i in 0 .. s - 1 -> List.nth xs i], [for i in s .. (List.length xs) - 1 -> List.nth xs i])
    

    the you just call

    let cut xs =                            
        gencut ((List.length xs) / 2) xs
    

    with n durationn only one iteration split in two

提交回复
热议问题