DEV Community

Discussion on: Daily Coding Puzzles - Nov 4th - Nov 9th

Collapse
 
kspeakman profile image
Kasey Speakman

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
    |]
Collapse
 
t4rzsan profile image
Jakob Christensen

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

(a |> Set.ofSeq) - (b |> Set.ofSeq)
Thread Thread
 
kspeakman profile image
Kasey Speakman

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

Thread Thread
 
rubberduck profile image
Christopher McClellan

Just define the subtraction operator and done.