Not sure how to implement the standard deviation through recursion

后端 未结 2 1580
说谎
说谎 2021-01-26 04:47

So I have the generic method set up consisting of:

  • A parameter of type T
  • A List of T\'s (which will be the data set that I will be looking at)
  • A
2条回答
  •  有刺的猬
    2021-01-26 05:44

    You don't need recursion. This could be computed using foldLeft:

    elements.foldLeft(0) {
       case (accumulator, item) => ...//calculate here next value from previously calculated 
                                      //value (accumulator) and current item
    }
    

提交回复
热议问题