From 59cd409130057078009edd47c5e4a74d8fa2d5e2 Mon Sep 17 00:00:00 2001 From: Travis CI Date: Sun, 31 Dec 2017 10:47:49 +0000 Subject: [PATCH] Travis build: 698 [ci skip] --- README.md | 75 +++++++++++++++++++++++-------------------------- docs/index.html | 20 ++++++------- 2 files changed, 45 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index f374490a5..23d3c641d 100644 --- a/README.md +++ b/README.md @@ -199,6 +199,7 @@ * [`orderBy`](#orderby) * [`select`](#select) * [`shallowClone`](#shallowclone) +* [`size`](#size) * [`truthCheckCollection`](#truthcheckcollection) @@ -258,15 +259,6 @@ -### _Uncategorized_ - -
-View contents - -* [`size`](#size) - -
- --- ## 🔌 Adapter @@ -3248,6 +3240,40 @@ a === b; // false
[⬆ Back to top](#table-of-contents) +### size + +Get size of arrays, objects or strings. + +Get type of `value` (`array`, `object` or `string`). +Use `length` property for arrays. +Use `length` or `size` value if available or number of keys for objects. +Use `size` of a [`Blob` object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) created from `value` for strings. + +Split strings into array of characters with `split('')` and return its length. + +```js +const size = value => + Array.isArray(value) + ? value.length + : value && typeof value === 'object' + ? value.size || value.length || Object.keys(value).length + : typeof value === 'string' ? new Blob([value]).size : 0; +``` + +
+Examples + +```js +size([1, 2, 3, 4, 5]); // 5 +size('size'); // 4 +size({ one: 1, two: 2, three: 3 }); // 3 +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### truthCheckCollection Checks if the predicate (second argument) is truthy on all elements of a collection (first argument). @@ -4305,37 +4331,6 @@ yesNo('Foo', true); // true
[⬆ Back to top](#table-of-contents) ---- - ## _Uncategorized_ - -### size - -Get size of arrays, objects or strings. - -Get type of `value` (`array`, `object` or `string`). -Use `length` property for arrays. -Use `length` or `size` value if available or number of keys for objects. -Use `size` of a [`Blob` object](https://developer.mozilla.org/en-US/docs/Web/API/Blob) created from `value` for strings. - -Split strings into array of characters with `split('')` and return its length. - -```js -const size = value => - Array.isArray(value) - ? value.length - : value && typeof value === 'object' - ? value.size || value.length || Object.keys(value).length - : typeof value === 'string' ? new Blob([value]).size : 0; -``` - -```js -size([1, 2, 3, 4, 5]); // 5 -size('size'); // 4 -size({ one: 1, two: 2, three: 3 }); // 3 -``` - -
[⬆ back to top](#table-of-contents) - ## Credits diff --git a/docs/index.html b/docs/index.html index 5d0befb5a..009792b77 100644 --- a/docs/index.html +++ b/docs/index.html @@ -59,7 +59,7 @@ wrapper.appendChild(box); box.appendChild(el); }); - }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
+    }

 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less.

 

Adapter

call

Given a key and a set of arguments, call them when given a context. Primarily useful in composition.

Use a closure to call a stored key with stored arguments.

const call = (key, ...args) => context => context[key](...args);
 
Promise.resolve([1, 2, 3])
   .then(call('map', x => 2 * x))
   .then(console.log); //[ 2, 4, 6 ]
@@ -647,6 +647,15 @@ select(obj, 'selector.to.val'); // 'val to select'
 
const a = { x: true, y: 1 };
 const b = shallowClone(a);
 a === b; // false
+

size

Get size of arrays, objects or strings.

Get type of value (array, object or string). Use length property for arrays. Use length or size value if available or number of keys for objects. Use size of a Blob object created from value for strings.

Split strings into array of characters with split('') and return its length.

const size = value =>
+  Array.isArray(value)
+    ? value.length
+    : value && typeof value === 'object'
+      ? value.size || value.length || Object.keys(value).length
+      : typeof value === 'string' ? new Blob([value]).size : 0;
+
size([1, 2, 3, 4, 5]); // 5
+size('size'); // 4
+size({ one: 1, two: 2, three: 3 }); // 3
 

truthCheckCollection

Checks if the predicate (second argument) is truthy on all elements of a collection (first argument).

Use Array.every() to check if each passed object has the specified property and if it returns a truthy value.

const truthCheckCollection = (collection, pre) => collection.every(obj => obj[pre]);
 
truthCheckCollection([{ user: 'Tinky-Winky', sex: 'male' }, { user: 'Dipsy', sex: 'male' }], 'sex'); // true
 

String

anagrams

Generates all anagrams of a string (contains duplicates).

Use recursion. For each letter in the given string, create all the partial anagrams for the rest of its letters. Use Array.map() to combine the letter with each partial anagram, then Array.reduce() to combine all anagrams in one array. Base cases are for string length equal to 2 or 1.

const anagrams = str => {
@@ -888,13 +897,4 @@ console.log(sdbm('age')); // 808122783
 yesNo('yes'); // true
 yesNo('No'); // false
 yesNo('Foo', true); // true
-

Uncategorized

size

Get size of arrays, objects or strings.

Get type of value (array, object or string). Use length property for arrays. Use length or size value if available or number of keys for objects. Use size of a Blob object created from value for strings.

Split strings into array of characters with split('') and return its length.

const size = value =>
-  Array.isArray(value)
-    ? value.length
-    : value && typeof value === 'object'
-      ? value.size || value.length || Object.keys(value).length
-      : typeof value === 'string' ? new Blob([value]).size : 0;
-
size([1, 2, 3, 4, 5]); // 5
-size('size'); // 4
-size({ one: 1, two: 2, three: 3 }); // 3
 

\ No newline at end of file