Comment detail

アレイのuniq (Nested Flatten)

This comment is reply for 481 ether: #456 は「配列状」を緩く解釈してリス...(アレイのuniq). Go to thread root.

関数型ということにこだわらなければこういう手も。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
open System;;
open Array;;

let uniq xs =
    let ars = create (length xs) xs.(0) in
    let i = ref 1 in
    for idx = 1 to (length xs)-1
    do
        if not (exists (fun elem -> xs.(idx) = elem) ars)
        then
            begin
                ars.(!i) <- xs.(idx);
                i := !i+1
            end
        else ()
    done;
    sub ars 0 !i;;

Index

Feed

Other

Link

Pathtraq

loading...