re: Daily Coding Puzzles - Nov 4th - Nov 9th VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Wednesday Array.diff (6 KYU): Your goal in this kata is to implement a difference function, which subtracts one list from another and returns th...
 

F#

let diff a b =
    a |> Array.filter (fun v -> not (b |> Array.contains v))

also sequence expression syntax

let diff a b =
    [|
        for value in a do
            if not (b |> Array.contains value) then
                yield value
    |]
 

Or (although it will also remove duplicates from a):

(a |> Set.ofSeq) - (b |> Set.ofSeq)

Yes, this was my first thought, but I was trying to retain dupes.

code of conduct - report abuse