-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path025.js
More file actions
38 lines (27 loc) · 731 Bytes
/
025.js
File metadata and controls
38 lines (27 loc) · 731 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
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
Project Euler Problem 25
Generated on : Sat Mar 14 2020
What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
*/
// Timing the execution :
let startTime = Date.now()
// Declaring functions
function fibonacciSequence(max) {
let index = 1
let a = BigInt(1);
let b = BigInt(1);
var nextNum = BigInt(0);
while (a.toString().length < max) {
nextNum = a + b;
a = b;
b = nextNum;
index++;
}
return index;
}
// Running with exercise specifics :
let result = fibonacciSequence(1000);
// Displaying result.
console.log(result);
// Display time the program ran.
console.log("Duration : ", Date.now() - startTime, "ms");