Skip to content

Instantly share code, notes, and snippets.

@kashsbd
Created August 19, 2024 10:23
Show Gist options
  • Save kashsbd/2accf2f953f0261c5ed3289a92888b7c to your computer and use it in GitHub Desktop.
Save kashsbd/2accf2f953f0261c5ed3289a92888b7c to your computer and use it in GitHub Desktop.
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