any ideas how can I write this method in a more fu...
# functional
h
any ideas how can I write this method in a more functional way? I tried using the
map
function but I have no idea how to keep track of
smallest
and
largest
like I do in a regular for loop:
Copy code
fun testFun(nums: IntArray): Int {
    var smallest = nums[0]
    var largest = nums[0]

    for (i in nums.indices) {
        smallest = Math.min(smallest, nums[i])
        largest = Math.max(largest, nums[i])
    }
    return largest - smallest
}