-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimes.js
More file actions
32 lines (24 loc) · 725 Bytes
/
times.js
File metadata and controls
32 lines (24 loc) · 725 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
/*
Write a function that calculates the time (in seconds) it takes for the JS code to calculate sum from 1 to n, given n as the input.
Try running it for
1. Sum from 1-100
2. Sum from 1-100000
3. Sum from 1-1000000000
Hint - use Date class exposed in JS
There is no automated test for this one, this is more for you to understand time goes up as computation goes up
*/
function calculateSum(n){
return 0.01;
}
let sum =0;
for (let i=1;i<=n;i++){
sum+=i;
}
return sum;
}
function calculateTime(n) {
const starting_time=new Date().getTime();
const result=calculateSum;
const endTime = new Date().getTime();
// const elapsedTimeInSeconds = (endTime - startTime) / 1000;
}