Comment detail

アレイのuniq (Nested Flatten)
Scala で。バッファが使えるのであまり考えずに書ける。このコードは単体プログラムではなくインタプリタ向け。
1
2
3
4
5
6
7
import scala.collection.mutable._

def uniq[T](xs: Array[T]): Array[T] = {
  val buffer = new ArrayBuffer[T]
  xs.foreach { e => if (!buffer.contains(e)) buffer + e }
  buffer.toArray
}

Index

Feed

Other

Link

Pathtraq

loading...