diff --git a/snippets/isArrayLike.md b/snippets/isArrayLike.md index 2a5c9ad09..83c8acb81 100644 --- a/snippets/isArrayLike.md +++ b/snippets/isArrayLike.md @@ -1,9 +1,11 @@ ### isArrayLike -Checks if the provided argument is `arrayLike` i.e. is iterable. +Checks if the provided argument is array-like (i.e. is iterable). + +Use `Array.from()` and a `try... catch` block to check if the provided argument is array-like. ```js -const arr = (arr) => { +const isArrayLike = arr => { try{ Array.from(arr); return true; diff --git a/snippets/isValidJSON.md b/snippets/isValidJSON.md index af9781a23..56211961b 100644 --- a/snippets/isValidJSON.md +++ b/snippets/isValidJSON.md @@ -1,11 +1,11 @@ ### isValidJSON -Checks if the provided argument is an valid JSON. - +Checks if the provided argument is a valid JSON. +Use `JSON.parse()` and a `try... catch` block to check if the provided argument is a valid JSON. ```js -const arr = (obj) => { +const isValidJSON = obj => { try{ JSON.parse(obj); return true; @@ -17,5 +17,6 @@ const arr = (obj) => { ``` ```js - +isValidJSON('{"name":"Adam","age":20}'); // true +isValidJSON('{"name":"Adam",age:"20"}'); // false ```