Ugly and longer one . :)

1
2
3
4
5
6
7
8
let goodValue (range:_ array) (badValue:_ array) =
    [|
        for i = 0 to range.Length - 1 do
            let bv = badValue.[i]
            match range.[i] with
            | a,b when a <= bv && bv <= b -> yield bv
            | a,b -> yield (a+b)/2.0
    |]
By on 1/31/2011 8:40 AM ()

Hello,
Thank you both.
Your codes work, I can see the difference between the two, but it doesn't matter, as long as it can solve my problem, it is a good solution.
Have a nice time!

By on 1/31/2011 9:28 AM ()

Try

1
2
Seq.zip range badValue
|> Seq.map (fun ((l, r), x) -> if x >= l && x <= r then x else (l+r)/2.0)

or even shorterSeq.map2 (fun (l, r) x -> if x >= l && x <= r then x else (l+r)/2.0) range badValue

or, if your result needs to be an arrayArray.map2 (fun (l, r) x -> if x >= l && x <= r then x else (l+r)/2.0) range badValue

By on 1/31/2011 8:25 AM ()
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