【发布时间】:2018-10-19 01:10:29
【问题描述】:
我有三个数组 - 第一个、第二个和第三个。 second 包含 first 和 third 的唯一值,通过映射到 second 包含用于替换 first 中的新值,如下所示:
module SOQN =
open System
let first = [|"A"; "B"; "C"; "A"; "B"; "A"; "C"; "B"; "C"; "C"; "C"|]
let second = [|"A"; "B"; "C"|]
let third = [|"1"; "2"; "3"|]
let rplc (x:string[]) (y:string[]) (z:string[]) =
first
// |> Array.map (fun w -> Array.iter2 (fun x y -> (if w = x then y)) second third)
let fourth =
rplc first second third
printfn ""
printfn "fourth: %A" fourth
// Expected Result: fourth: [|"1"; "2"; "3"; "1"; "2"; "1"; "3"; "2"; "3"; "3"; "3"|]
// Actual Result: fourth: [|"A"; "B"; "C"; "A"; "B"; "A"; "C"; "B"; "C"; "C"; "C"|]
我的注释行失败,但我不知道为什么?
【问题讨论】:
-
你应该从第二个和第三个列表创建一个字典/映射,然后使用第一个列表作为键。
标签: arrays replace f# match unique