JSFiddle - React, Tailwind, and code Playground
by Trevor W
JavaScript
let foo = [0,1,2,3,4,5,6,7,8,9,10];
function getAverageChangeOverTime(historicalPrices,index,lookback,dataPiece){
if(historicalPrices[index - lookback - 1] === undefined){
return false;
}
let results = [];
let startPos = index - lookback;
while(startPos < index){
let currentValue = historicalPrices[startPos];
let compareValue = historicalPrices[startPos - 1];
results.push("compareValue("+compareValue+") currentValue("+currentValue+")");
}
return results;
}
let bar = getAverageChangeOverTime(foo,5,4,1);
console.log("bar",bar);