From bc5bea609fd86a47124d2491f6cdec1b7cfd22ee Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Tue, 2 Jan 2018 10:48:08 +0200 Subject: [PATCH] Updated to use @skatcat31's suggestion --- snippets/once.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/snippets/once.md b/snippets/once.md index 01d6216d1..18e5fc886 100644 --- a/snippets/once.md +++ b/snippets/once.md @@ -6,15 +6,7 @@ Utilizing a closure, use a flag, `called`, and set it to `true` once the functio Allow the function to be supplied with an arbitrary number of arguments using the spread (`...`) operator. ```js -const once = fn => { - let called = false; - return (...args) => { - if (!called) { - fn(...args); - called = true; - } - }; -}; +const once = fn => (called => (...args) => !called ? (called = true, fn(...args)) : undefined)() ``` ```js