From dcea680b08184398a5e72ffdb494ba79aecd3cd9 Mon Sep 17 00:00:00 2001 From: Christopher Engels Date: Tue, 12 Dec 2017 19:18:53 +0100 Subject: [PATCH] Refactor measure-time-taken-by-function from spread syntax to callback function --- snippets/measure-time-taken-by-function.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/snippets/measure-time-taken-by-function.md b/snippets/measure-time-taken-by-function.md index 8586f59d1..4b9fe33a2 100644 --- a/snippets/measure-time-taken-by-function.md +++ b/snippets/measure-time-taken-by-function.md @@ -4,10 +4,10 @@ Use `performance.now()` to get start and end time for the function, `console.log First argument is the function name, subsequent arguments are passed to the function. ```js -const timeTaken = (func,...args) => { - var t0 = performance.now(), r = func(...args); +const timeTaken = callback => { + const t0 = performance.now(), r = callback(); console.log(performance.now() - t0); return r; } -// timeTaken(Math.pow, 2, 10) -> 1024 (0.010000000009313226 logged in console) +// timeTaken(() => Math.pow(2, 10)) -> 1024 (0.010000000009313226 logged in console) ```