Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions 01-js/medium/times.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
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
*/


function calculateTime(n) {
return 0.01;
}
var startTime=performance.now();
var sum=0;
for(var i=1;i<=n;i++){
sum+=i;
}
var endTime=performance.now();
var timePassed=(endTime-startTime)/1000;
return timePassed;
}