This smells a little bit like homework, but it sounds like you're on the right track. Array.choose and Array.filter are good ways to start with an array and wind up with a smaller array.

Since you have 2 arrays to start, a common idiom is to first combine them into one array of tuples, and then process the combined array. The code below shows a couple ways you can combine them (via either 'map2' or 'zip'). Once you have the 'both' array, do you see a way to use choose or filter to get the final answer?

let choseArray = [| 1; 1; 0 |]
let totalArray = [| "A"; "B"; "C" |]

//let both = Array.map2 (fun x y -> (x,y)) choseArray totalArray
let both = Array.zip choseArray totalArray
printfn "%A" both // [|(1, "A"); (1, "B"); (0, "C")|]

By on 10/16/2010 10:27 AM ()

Hello,
Thank you very much.
I have figured out:

let pickArray = Array.choose(fun elem -> if fst(elem) = 1 then Some(snd(elem))
else None) both
printfn "PickArray = %A" pickArray

It seems to be easy, but difficult to firuge out, esp. when I don't know how to make the "both" Array.
Thanks again!

By on 10/16/2010 12:07 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper