Created
September 29, 2017 09:26
-
-
Save slavafomin/b3de060ee559bc48980b9d2a87bbf946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const requests = [ | |
{requestId: 't2', startedAt: 1489744808, ttl: 8}, | |
{requestId: 't3', startedAt: 1489744803, ttl: 3}, | |
{requestId: 't1', startedAt: 1489744806, ttl: 12}, | |
{requestId: 't4', startedAt: 1489744810, ttl: 1} | |
]; | |
let min = requests[0].startedAt; | |
let max = 0; | |
requests.forEach(request => { | |
const completeAt = request.startedAt + request.ttl; | |
if (request.startedAt < min) { | |
min = request.startedAt; | |
} | |
if (completeAt > max) { | |
max = completeAt; | |
} | |
}); | |
const cummulativeTtl = (max - min); | |
console.log(cummulativeTtl); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment