#Yet another way to avoid return
Yet another way to avoid return
You know you should use eval for arrow functions with multiple statements and a return. In some unusual case you can save more using an inner subfunction.
I say unusual because
The result returned must not be the last expression evalued in the loop
There must be (at least) 2 different initializations before the loop
In this case you can use an inner subfunction without return, having one of the initial values passed as a parameter.
Example Find the reciprocal of the sum of exp function for values in a range from a to b.
The long way - 55 bytes
(a,b)=>{for(r=0,i=a;i<=b;i++)r+=Math.exp(i);return 1/r}
With eval - 54 bytes
(a,b)=>eval("for(r=0,i=a;i<=b;i++)r+=Math.exp(i);1/r")
With an inner function - 53 bytes
(a,b)=>(i=>{for(r=0;i<=b;i++)r+=Math.exp(i)})(a)||1/r
Note that without the requirement of a lower range limit a
, I can merge the initializations of i and r and the eval version is shorter.