码迷,mamicode.com
首页 > 其他好文 > 详细

ProductByFoldLeft

时间:2016-04-19 22:47:17      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

object ProductByFoldLeft {

  def product(as: List[Double]): Double = FoldLeft.foldLeft(as, 1.0)(_ * _)

  def main(args: Array[String]): Unit = {
    println(product(List(1.0, 2, 3, 4, 5)))
    println(product(List(1.0)))
    println(product(List(1, 2, 0.0, 4, 5)))
  }

}
120.0
1.0
0.0

 

ProductByFoldLeft

标签:

原文地址:http://www.cnblogs.com/JonkeyGuan/p/5410440.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!