A performance overlay draws a smooth line through frame times. Each point of the line is the average of k frame times in a row.
Write movingAverage(frameTimes, k) that returns an array with the average of every window of k consecutive frame times, from the first window to the last. If there are fewer than k frame times, return []. Answers within 0.00001 of the exact value are accepted.
Input: frameTimes = [16,17,33,16,18], k = 2 Output: [16.5,25,24.5,17]
For example the first window is (16 + 17) / 2 = 16.5.
Input: frameTimes = [10,20], k = 3 Output: []
There aren't enough frames for one window.
0 <= frameTimes.length <= 1000001 <= k <= 10000 <= frameTimes[i] <= 1000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #125 Frame Time Moving Average. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.