如何调整可迭代数组的功能?

时间:2019-06-20 08:43:25

标签: arrays scala function iterator rdd

1974,1974-06-22 1966,1966-07-20 1954,1954-06-19 1994,1994-06-27 1954,1954-06-26 2006,2006-07-04 2010,2010-07-07 1990,1990-06-30 ...

It is type RDD[String].

What is wrong in the function iteself?

1 个答案:

答案 0 :(得分:0)

尝试

def f(v: Iterable[Array[String]]): Int = {
  val parsedDates = v.flatten.map(e => LocalDate.parse(e, formatter))
  parsedDates.max.getDayOfYear - parsedDates.min.getDayOfYear
}

输出

val arrays = Iterable(Array("2014-10-10","2014-12-10"))
f(arrays) // res0: Int = 61