From 492c63358bccc8095a8e9943d42727f47c1d0d1e Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Mon, 1 Jan 2018 14:45:17 +0200 Subject: [PATCH] Update isArrayLike.md --- snippets/isArrayLike.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/snippets/isArrayLike.md b/snippets/isArrayLike.md index 8d846e68f..b5fe545e8 100644 --- a/snippets/isArrayLike.md +++ b/snippets/isArrayLike.md @@ -2,15 +2,13 @@ Checks if the provided argument is array-like (i.e. is iterable). -Check that the object is not a function or `null` and that its `length` property is a non-negative integer below `Number.MAX_SAFE_INTEGER`. +Use the spread operator (`...`) to check if the provided argument is iterable inside a `try... catch` block and the comma operator (`,`) to return the appropriate value. ```js const isArrayLike = val => - val != null && - typeof val != 'function' && - val.length > -1 && - val.length % 1 == 0 && - val.length <= Number.MAX_SAFE_INTEGER; + try {return [...val], true; } + catch (e) { return false; } +}; ``` ```js