Created
January 10, 2018 01:08
-
-
Save gmittal/41442bbeafb83c9cdedcd3328d30dbbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* http://paleyontology.com/AP_CS/rainfall.html | |
*/ | |
let lyst = [-76, 0, -1, 1, 2, -999]; | |
function rainfall(nums) { | |
nums = nums.splice(0, nums.indexOf(-999)); | |
const positive = nums.filter(n => n >= 0); | |
return positive.reduce((total, n) => { | |
total += n; | |
return total | |
})/positive.length; | |
} | |
console.log(rainfall(lyst)); // returns 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment