Skip to content

Instantly share code, notes, and snippets.

@johnwcothran
Last active September 27, 2018 15:47
Show Gist options
  • Save johnwcothran/018bc7e6e2ad5cdf3862ed89815ef8e6 to your computer and use it in GitHub Desktop.
Save johnwcothran/018bc7e6e2ad5cdf3862ed89815ef8e6 to your computer and use it in GitHub Desktop.
import R from 'ramda';
function ewa (decay, data, arr=[]) {
const beta = Math.E**(-1/decay);
const checkArr = (b) => {
return arr.length === 0
? R.prop('value', data[1])
: R.prop('value', arr[R.length(arr)-1]) * b + R.prop('value', data[1]) * (1-b)
};
if (R.length(data) === 0) return arr;
return ewa(
decay,
R.tail(data),
R.append(
R.pipe(
R.assoc('value', checkArr(beta)),
R.assoc('label', `${decay} Day`),
)(data[1]),
arr
),
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment