Skip to content

Instantly share code, notes, and snippets.

@gregtatum
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save gregtatum/048c1f389b22eac4580d to your computer and use it in GitHub Desktop.

Select an option

Save gregtatum/048c1f389b22eac4580d to your computer and use it in GitHub Desktop.
Calculate e constant
var e = function( iterations ) {
var aggregator = 1
for( var i=1; i < iterations; i++ ) {
var value=1;
for( var j=2; j <= i; j++ ) {
value *= 1 / j
}
aggregator += value
}
return aggregator
}
@gregtatum
Copy link
Author

e(1)
> 1
e(2)
> 2
e(3)
> 2.5
e(4)
> 2.6666666666666665
e(5)
> 2.708333333333333
e(6)
> 2.7166666666666663
e(7)
> 2.7180555555555554
e(8)
> 2.7182539682539684
e(9)
> 2.71827876984127
e(10)
> 2.7182815255731922
e(50)
> 2.7182818284590455
e(100)
> 2.7182818284590455
e(1000)
> 2.7182818284590455

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment