Skip to content

Commit baf8f9e

Browse files
committed
refa: use custom toLocale function
1 parent 6e67d33 commit baf8f9e

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Diff for: lib/time.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,32 @@ const timeRepo = (algos, args, runs, id) => {
8080
return { id, sortedTimes, args, runs }
8181
}
8282

83+
/**
84+
* Builds a locale string with type information.
85+
*
86+
* @param {any} val Value to convert to locale string.
87+
* @returns {string} A locale string with type information.
88+
*/
89+
const toLocaleString = (val) => {
90+
if (Array.isArray(val)) {
91+
return `[${val.toLocaleString()}]`
92+
}
93+
94+
return val.toLocaleString()
95+
}
96+
8397
/**
8498
* Parses a result object into a print-friendly string.
8599
*
86100
* @param {TimeRepoResult} result Result to be parsed.
87101
* @returns {string} A print-friendly string.
88102
*/
89103
const parseResult = ({ id, sortedTimes, args, runs }) => {
90-
const strArgs = args.map(arg => arg.toLocaleString())
104+
const strArgs = args.map(arg => `\n ${toLocaleString(arg)}`)
91105
const strRuns = runs.toLocaleString()
92106

93107
let parsedResult =
94-
`${id}\nargument list: (${strArgs})\nnumber of runs: ${strRuns}\n\n`
108+
`${id}\nargument list: ${strArgs}\nnumber of runs: ${strRuns}\n\n`
95109

96110
for (let idx = 0; idx < sortedTimes.length; idx++) {
97111
const left = `${idx + 1}: ${sortedTimes[idx][1].toFixed(3)} ms - `

0 commit comments

Comments
 (0)