Created
June 25, 2021 14:51
-
-
Save tenorok/e840e3dc5ba34cc074b7de41876d17d5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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