I have been playing with the following function:
s = function(x) {
for(n=10,z=0;~(--n);){
z+=pow(-1,n)/fac(2*n+1)*pow(x,2*n+1)
}
return z
}
fac is a factorial function, pow is a power function (for those playing at home) which I have defined outside of this function. s is meant to be a Taylor series derivation of the sine function, so s(Math.PI/4)
would come back as a very close approximation of the square root of 0.5.
I'd like to make this an arrow function with z automatically returning, but have found myself failing at this point with an "Invalid left-hand side expression in prefix operation" error...
I received this error when I tried:
s=x=>~(--(n=n||10))?s((z=z||0)+=pow(-1,n)/fac(2*n+1)*pow(x,2*n+1)):z
I know I'm missing something ridiculous... but I can't put my finger on it... Can anyone lend a hand?
Thanks in advance.