2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,10 +1,19 @@
|
|||
// single-sided
|
||||
Array.prototype.simpleSMA=function(N) {
|
||||
return this.map(function(x,i,v) {
|
||||
if(i<N-1) return NaN;
|
||||
return v.filter(function(x2,i2) { return i2<=i && i2>i-N; }).reduce(function(a,b){ return a+b; })/N;
|
||||
}); };
|
||||
return this.map(
|
||||
function(el,index, _arr) {
|
||||
return _arr.filter(
|
||||
function(x2,i2) {
|
||||
return i2 <= index && i2 > index - N;
|
||||
})
|
||||
.reduce(
|
||||
function(current, last, index, arr){
|
||||
return (current + last);
|
||||
})/index || 1;
|
||||
});
|
||||
};
|
||||
|
||||
g=[1,2,3,4,5,8,5,4];
|
||||
console.log(g.simpleSMA(3))
|
||||
console.log(g.simpleSMA(5))
|
||||
g=[0,1,2,3,4,5,6,7,8,9,10];
|
||||
console.log(g.simpleSMA(3));
|
||||
console.log(g.simpleSMA(5));
|
||||
console.log(g.simpleSMA(g.length));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue