Search code examples
arraysscalafunctioniteratorrdd

How to adjust function for Iterable Array?


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?

Solution

  • Try

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

    which outputs

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