Add some examples

From the old test suite
This commit is contained in:
Angelos Chalaris
2020-04-16 23:01:19 +03:00
parent 719cc00a53
commit 5e42f0aaa4
5 changed files with 11 additions and 6 deletions

View File

@ -23,4 +23,5 @@ const equals = (a, b) => {
```js
equals({ a: [2, { e: 3 }], b: [4], c: 'foo' }, { a: [2, { e: 3 }], b: [4], c: 'foo' }); // true
equals([ 1, 2, 3 ], { 0: 1, 1: 2, 2: 3 }); // true
```

View File

@ -5,14 +5,14 @@ tags: type,beginner
Returns the native type of a value.
Return `"undefined"` or `"null"` if the value is `undefined` or `null`.
Otherwise, use `Object.prototype.constructor.name` to get the name of the constructor, `String.prototype.toLowerCase()` to return it in lowercase.
Return `'undefined'` or `'null'` if the value is `undefined` or `null`.
Otherwise, use `Object.prototype.constructor.name` to get the name of the constructor.
```js
const getType = v =>
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name.toLowerCase();
v === undefined ? 'undefined' : v === null ? 'null' : v.constructor.name;
```
```js
getType(new Set([1, 2, 3])); // 'set'
getType(new Set([1, 2, 3])); // 'Set'
```

View File

@ -12,6 +12,7 @@ const isArrayLike = obj => obj != null && typeof obj[Symbol.iterator] === 'funct
```
```js
isArrayLike([1, 2, 3]); // true
isArrayLike(document.querySelectorAll('.className')); // true
isArrayLike('abc'); // true
isArrayLike(null); // false

View File

@ -14,4 +14,5 @@ const isNil = val => val === undefined || val === null;
```js
isNil(null); // true
isNil(undefined); // true
isNil(''); // false
```

View File

@ -13,9 +13,11 @@ const isPrimitive = val => Object(val) !== val;
```js
isPrimitive(null); // true
isPrimitive(undefined); // true
isPrimitive(50); // true
isPrimitive('Hello!'); // true
isPrimitive(false); // true
isPrimitive(Symbol()); // true
isPrimitive([]); // false
isPrimitive({}); // false
```