Comment detail

重複する要素を取り除く (Nested Flatten)

This comment is reply for 2850 にしお: パターンマッチがうらやましい…(重複する要素を取り除く). Go to thread root.

そこでScalaですよ。

同じやり方で書いてみました。

1
2
3
4
def uniqOnly[A](xs:List[A]) =  
  for(x::Nil <- (for(y<-xs) yield (for(z<-xs if z==y) yield z))) yield x

println(uniqOnly(List(3, 1, 4, 1, 5, 9, 2, 6, 5)))

Index

Feed

Other

Link

Pathtraq

loading...