Skip to content

Instantly share code, notes, and snippets.

@tenorok
Created June 25, 2021 14:51
Show Gist options
  • Save tenorok/e840e3dc5ba34cc074b7de41876d17d5 to your computer and use it in GitHub Desktop.
Save tenorok/e840e3dc5ba34cc074b7de41876d17d5 to your computer and use it in GitHub Desktop.
function SMA(list, interval) {
const result = [];
for (let i = 0; i <= list.length - interval; i++) {
let sum = 0;
for (let j = i; j < i + interval; j++) {
sum += list[j];
}
result.push(sum / interval);
}
return result;
}
function WMA(list, interval) {
const result = [];
for (let i = 0; i <= list.length - interval; i++) {
let sum = 0;
let denominator = 0;
for (let j = i, n = 1; j < i + interval; j++, n++) {
sum += list[j] * n;
denominator += n;
}
result.push(sum / denominator);
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment