• + 0 comments

    Scala

    def checkHeadLessThanDelim(delim: Int, head: Int, result: List[Int]
                              ): List[Int] = {
        if (head < delim) {
            result :+ head
        } else {
            result
        }
    }
    
    def f(delim: Int, arr: List[Int], result: List[Int] = List(),
         headChecker: (Int, Int, List[Int]) => List[Int] = checkHeadLessThanDelim
         ): List[Int] = {
        if (arr.size > 0) {
            f(delim, arr.tail, headChecker(delim, arr.head, result))
        } else {
            result
        }
    }