-
-
Save korepwx/2c4c63741fed0effdd70f3bf80070530 to your computer and use it in GitHub Desktop.
A short snippet of JS code
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
function f(arr) { | |
if (arr.length < 10) { | |
var acc = 0; | |
for (var i=0; i<arr.length; ++i) { | |
acc += arr[i]; | |
} | |
return [acc / arr.length]; | |
} else { | |
var acc = 0; | |
var ret = []; | |
for (var i=0; i<10; ++i) { | |
acc += arr[i]; | |
} | |
ret[0] = acc / 10; | |
for (var i=10; i<arr.length; ++i) { | |
acc = acc - arr[i-10] + arr[i]; | |
ret[i-9] = acc / 10; | |
} | |
return ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment