Skip to content

Instantly share code, notes, and snippets.

@lukasa1993
Created February 15, 2018 12:02
Show Gist options
  • Save lukasa1993/bd82d1cc639b5c077951c339506370ef to your computer and use it in GitHub Desktop.
Save lukasa1993/bd82d1cc639b5c077951c339506370ef to your computer and use it in GitHub Desktop.
const timer = [];
module.exports = {
step: (key) => {
timer.push({
key: key,
time: new Date().getTime()
});
},
view: () => {
const result = [];
let total = 0;
for (let i = 0, len = timer.length; i < len; i++) {
if (i === 0) {
result.push(timer[0].key + ' - ' + 0);
} else {
result.push(timer[i].key + ' - ' + (timer[i].time - timer[i - 1].time));
total += timer[i].time - timer[i - 1].time;
}
}
result.push('Total - ' + total);
return result;
},
reset: () => {
timer.splice(0, timer.length);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment