forked from TheAlgorithms/JavaScript
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExponentialFunction.js
More file actions
Latest commit
25 lines (24 loc) · 651 Bytes
/
Copy pathExponentialFunction.js
File metadata and controls
25 lines (24 loc) · 651 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/**
* @function exponentialFunction
* @description Calculates the n+1 th order Taylor series approximation of exponential function e^x given n
* @param {Integer} power
* @param {Integer} order - 1
* @returns exponentialFunction(2,20) = 7.3890560989301735
* @url https://en.wikipedia.org/wiki/Exponential_function
*/
functionexponentialFunction(power,n){
letoutput=0
letfac=1
if(isNaN(power)||isNaN(n)||n<0){
thrownewTypeError('Invalid Input')
}
if(n===0){
return1
}
for(leti=0;i<n;i++){
output+=power**i/fac
fac*=i+1
}
returnoutput
}
export{exponentialFunction}