Created
August 19, 2024 10:23
-
-
Save kashsbd/2accf2f953f0261c5ed3289a92888b7c to your computer and use it in GitHub Desktop.
This file contains 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 calculateExecutionTimes = (input) => { | |
const map = {}; | |
for(let i=0; i < input.length; i++) { | |
const item = input[i]; | |
if(map[item.name]) { | |
map[item.name] = Math.abs(item.time - map[item.name]); | |
} else { | |
map[item.name] = item.time; | |
} | |
} | |
return map; | |
} | |
const input = [ | |
{ name: "main", time: 25, event: "end" }, | |
{ name: "main", time: 0, event: "start" }, | |
{ name: "subTask1", time: 5, event: "start" }, | |
{ name: "subTask2", time: 15, event: "start" }, | |
{ name: "subTask2", time: 20, event: "end" }, | |
] | |
console.log(calculateExecutionTimes(input)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment