Easy
This question is a daily question and will count towards your daily streak.
You are building a real-time stock price tracker. The goal is to calculate the moving average of the last n prices whenever a new price is added. The function updatePrices takes a list of prices and a window size n. Which implementation correctly calculates the moving average?
1function updatePrices(prices, newPrice, n) {2 prices.push(newPrice);34 /* Missing Code Here */5}67let prices = [100, 102, 105, 110];8updatePrices(prices, 108, 3);