Created
February 15, 2018 12:02
-
-
Save lukasa1993/bd82d1cc639b5c077951c339506370ef 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 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