Skip to content

Instantly share code, notes, and snippets.

@klinquist
Created February 6, 2020 01:23
Show Gist options
  • Save klinquist/1d2fe03080d7c188df391cd93c91d767 to your computer and use it in GitHub Desktop.
Save klinquist/1d2fe03080d7c188df391cd93c91d767 to your computer and use it in GitHub Desktop.
const getEntryEveryMinutes = 5;
const randomNumber = (min, max) => {
return Math.floor(Math.random() * (max - min) + min);
};
const myArray = [];
setInterval(() => {
myArray.push(randomNumber(1,100));
if (myArray.length == 13) myArray.shift();
let total = 0;
for (let i = 0; i < myArray.length; i++){
total = total + myArray[i];
}
const avg = Math.round(total / myArray.length);
console.log(`Running average is ${avg}. Number of items in array ${myArray.length}`);
}, getEntryEveryMinutes*60*1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment