-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
35 lines (30 loc) · 758 Bytes
/
Copy pathutils.js
File metadata and controls
35 lines (30 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function range(start, end) {
return Array(Math.max(start, end) - Math.min(start, end) + 1)
.fill(0)
.map((_, index) => Math.min(start, end) + index);
}
function sum(array) {
return array.reduce((sum, current) => current + sum, 0);
}
// Stolen from Alexander Rose
function startTimer() {
return process.hrtime();
}
function endTimer(time) {
function roundTo(decimalPlaces, numberToRound) {
return +(
Math.round(numberToRound + `e+${decimalPlaces}`) + `e-${decimalPlaces}`
);
}
const diff = process.hrtime(time);
const NS_PER_SEC = 1e9;
const result = diff[0] * NS_PER_SEC + diff[1];
const elapsed = result * 0.000001;
return roundTo(6, elapsed);
}
module.exports = {
range,
startTimer,
endTimer,
sum,
};