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. Search for snippet...
Adapter call collectInto flip pipeFunctions promisify spreadOver Array chunk compact countOccurrences deepFlatten difference differenceWith distinctValuesOfArray dropElements dropRight everyNth filterNonUnique flatten flattenDepth groupBy head initial initialize2DArray initializeArrayWithRange initializeArrayWithValues intersection last mapObject nthElement pick pull pullAtIndex pullAtValue quickSort remove sample shuffle similarity symmetricDifference tail take takeRight union without zip zipObject Browser arrayToHtmlList bottomVisible copyToClipboard currentURL detectDeviceType elementIsVisibleInViewport getScrollPosition getStyle getURLParameters hasClass hide httpsRedirect onUserInputChange redirect scrollToTop setStyle show speechSynthesis toggleClass UUIDGeneratorBrowser Date getDaysDiffBetweenDates JSONToDate toEnglishDate tomorrow Function chainAsync compose curry functionName runPromisesInSeries sleep Logic negate Math average clampNumber collatz digitize distance factorial fibonacci fibonacciCountUntilNum fibonacciUntilNum gcd hammingDistance inRange isArmstrongNumber isDivisible isEven isPrime lcm max median min percentile powerset primes randomIntegerInRange randomNumberInRange round standardDeviation sum Node JSONToFile readFileLines UUIDGeneratorNode Object cleanObj lowercaseKeys objectFromPairs objectToPairs orderBy select shallowClone truthCheckCollection String anagrams byteSize capitalize capitalizeEveryWord countVowels escapeHTML escapeRegExp fromCamelCase palindrome repeatString reverseString sortCharactersInString splitLines toCamelCase toKebabCase toSnakeCase truncateString unescapeHTML words Utility coalesce coalesceFactory extendHex getType hexToRGB isArray isBoolean isFunction isNull isNumber isString isSymbol randomHexColorCode RGBToHex sdbm timeTaken toDecimalMark toOrdinalSuffix validateNumber yesNo Uncategorized size 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 ]
@@ -888,4 +888,13 @@ 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
diff --git a/snippets/size.md b/snippets/size.md
index 92b3a34a1..1c3127929 100644
--- a/snippets/size.md
+++ b/snippets/size.md
@@ -14,14 +14,12 @@ 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;
+ ? 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([1, 2, 3, 4, 5]); // 5
size('size'); // 4
size({ one: 1, two: 2, three: 3 }); // 3
```
diff --git a/tag_database b/tag_database
index 5bcb338a5..4b47db2fc 100644
--- a/tag_database
+++ b/tag_database
@@ -121,6 +121,7 @@ shallowClone:object
show:browser
shuffle:array
similarity:array
+size:uncategorized
sleep:function
sortCharactersInString:string
speechSynthesis:browser