e.g.快速排序
def qSort(x: List[Int]):List[Int] = {
if (x.length<=1) x
else
qSort(x.filter(_ < x.head)) ++
x.filter(_ == x.head) ++
qSort(x.filter(_ > x.head))
}
def qSort(x: List[Int]):List[Int] = {
if (x.length<=1) x
else
qSort(x.filter(_ < x.head)) ++
x.filter(_ == x.head) ++
qSort(x.filter(_ > x.head))
}
2017-09-27
缺失部分
例子1: (x: Int) => x*x
例子2: (x: Int,y: Int) => x+y
例子3:
var add = (x: Int,y: Int)=> x+y //add是一个具有函数类型的变量
add(1,2) //返回值:Int=3
def greeting() = (name:String) => {s"Hello $name"}
greeting()("World")
def greeting(age: Int) = (name:String) => {s"Hello $name,your age is $age"}
greeting(23)("Flygar")
例子1: (x: Int) => x*x
例子2: (x: Int,y: Int) => x+y
例子3:
var add = (x: Int,y: Int)=> x+y //add是一个具有函数类型的变量
add(1,2) //返回值:Int=3
def greeting() = (name:String) => {s"Hello $name"}
greeting()("World")
def greeting(age: Int) = (name:String) => {s"Hello $name,your age is $age"}
greeting(23)("Flygar")
2017-09-27
这大早晨的,来一句烧脑的代码:def sumSq(in : List[Int]): (Int, Int, Int) = in.foldLeft((0,0,0))((t,v) => (t._1 + 1, t._2 + v, t._3 + v*v)) orz
2017-09-08
http://docs.scala-lang.org/zh-cn/overviews/collections/introduction.html
2017-09-06