Daily Coding Problem: Problem #671

/**
 * This problem was asked by Facebook.
Given a function f, and N return a debounced f of N milliseconds.
That is, as long as the debounced f continues to be invoked, f itself will not be called for N milliseconds.
 * */
class Problem_671 {
    /*
    * parameter 1: function f
    * parameter 2: N, milliseconds
    * */
    fun debounced(f: () -> Unit, N: Int) {
        var currentTime = 0L
        val startTime = System.currentTimeMillis()
        if (currentTime == 0L || (startTime - currentTime) >= N) {
            f()
            currentTime = System.currentTimeMillis()
        }
    }

    fun functionF() {
        println("call me")
    }
}
原文地址:https://www.cnblogs.com/johnnyzhao/p/13760490.html