DEV Community

Discussion on: Daily Coding Puzzles - Oct 29th - Nov 2nd

Collapse
 
kspeakman profile image
Kasey Speakman • Edited

F#

let update (count, sum) value =
    if value > 0 then (count + 1), sum
    else              count, (sum + value)

// usage, start with 0 count/sum, update them for each value
let (count, sum) = Array.fold update (0, 0) inputArr

This returns a tuple instead of an array, which I believe is an improvement.