-2

Say array1=[|1;2;3;4;5;6|],array2=[|7;6;5;4;3|]
basically, I want an array which contains the common elements of array1 and array2 AND in the sorted as array1.
In this case, I should return array [|3;4;5;6|]. Can anyone help?

4

1 回答 1

3

A simple solution:

 array1 |> Array.filter (fun t -> array2 |> Array.exists (fun t2 -> t=t2))

this gets the correct sort order for free.

于 2013-01-07T07:11:00.157 回答