From 31f7c652e283518881a429448e09ef5f26dfe9ed Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 13 Dec 2017 13:55:44 +0200 Subject: [PATCH] Build README --- README.md | 8 ++++---- snippets/measure-time-taken-by-function.md | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 303f34e39..dffb8d999 100644 --- a/README.md +++ b/README.md @@ -385,15 +385,15 @@ const last = arr => arr.slice(-1)[0]; ### Measure time taken by function Use `performance.now()` to get start and end time for the function, `console.log()` the time taken. -First argument is the function name, subsequent arguments are passed to the function. +Pass a callback function as the argument. ```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) ``` ### Median of array of numbers diff --git a/snippets/measure-time-taken-by-function.md b/snippets/measure-time-taken-by-function.md index 4b9fe33a2..73d32141e 100644 --- a/snippets/measure-time-taken-by-function.md +++ b/snippets/measure-time-taken-by-function.md @@ -1,7 +1,7 @@ ### Measure time taken by function Use `performance.now()` to get start and end time for the function, `console.log()` the time taken. -First argument is the function name, subsequent arguments are passed to the function. +Pass a callback function as the argument. ```js const timeTaken = callback => {