diff --git a/snippets/isArrayLike.md b/snippets/isArrayLike.md index 5417f1974..5e44bb473 100644 --- a/snippets/isArrayLike.md +++ b/snippets/isArrayLike.md @@ -2,16 +2,8 @@ Checks if the provided argument is array-like (i.e. is iterable). -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 => { - try { - return [...val], true; - } catch (e) { - return false; - } -}; +const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'function'; ``` ```js diff --git a/test/isArrayLike/isArrayLike.js b/test/isArrayLike/isArrayLike.js index c603d5bc5..144b181d0 100644 --- a/test/isArrayLike/isArrayLike.js +++ b/test/isArrayLike/isArrayLike.js @@ -1,8 +1,2 @@ -const isArrayLike = val => { - try { - return [...val], true; - } catch (e) { - return false; - } -}; +const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'function'; module.exports = isArrayLike;