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 forEachRight groupBy head indexOfAll initial initialize2DArray initializeArrayWithRange initializeArrayWithValues intersection isSorted join last longestItem mapObject maxN minN nthElement partition pick pull pullAtIndex pullAtValue reducedFilter remove sample sampleSize shuffle similarity sortedIndex symmetricDifference tail take takeRight union without zip zipObject Browser arrayToHtmlList bottomVisible copyToClipboard createElement createEventHub currentURL detectDeviceType elementIsVisibleInViewport getScrollPosition getStyle hasClass hide httpsRedirect off on onUserInputChange redirect runAsync scrollToTop setStyle show toggleClass UUIDGeneratorBrowser Date formatDuration getDaysDiffBetweenDates tomorrow Function chainAsync compose curry defer functionName memoize negate once runPromisesInSeries sleep Math average averageBy clampNumber digitize distance elo factorial fibonacci gcd geometricProgression hammingDistance inRange isDivisible isEven isPrime lcm luhnCheck maxBy median minBy percentile powerset primes randomIntegerInRange randomNumberInRange round sdbm standardDeviation sum sumBy sumPower toSafeInteger Node hasFlags isTravisCI JSONToFile readFileLines untildify UUIDGeneratorNode Object cleanObj invertKeyValues lowercaseKeys objectFromPairs objectToPairs orderBy select shallowClone size truthCheckCollection String anagrams byteSize capitalize capitalizeEveryWord decapitalize escapeHTML escapeRegExp fromCamelCase isAbsoluteURL isLowerCase isUpperCase mask palindrome pluralize reverseString sortCharactersInString splitLines toCamelCase toKebabCase toSnakeCase truncateString unescapeHTML words Type getType isArray isArrayLike isBoolean isFunction isNull isNumber isPrimitive isPromiseLike isString isSymbol isValidJSON Utility cloneRegExp coalesce coalesceFactory extendHex getURLParameters hexToRGB httpGet httpPost prettyBytes randomHexColorCode RGBToHex timeTaken toDecimalMark toOrdinalSuffix validateNumber yesNo 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);
Show examples Promise. resolve ([ 1 , 2 , 3 ])
. then ( call ( 'map' , x => 2 * x))
. then ( console. log);
@@ -125,11 +125,6 @@ Object. assig
: arr. reduce (( a, v) => a. concat ( v), []);
Show examples flatten ([ 1 , [ 2 ], 3 , 4 ]);
flatten ([ 1 , [ 2 , [ 3 , [ 4 , 5 ], 6 ], 7 ], 8 ], 2 );
-📋 Copy to clipboard flattenDepth Flattens an array up to the specified depth.
Use recursion, decrementing depth by 1 for each level of depth. Use Array.reduce() and Array.concat() to merge elements or arrays. Base case, for depth equal to 1 stops recursion. Omit the second element, depth to flatten only to a depth of 1 (single flatten).
const flattenDepth = ( arr, depth = 1 ) =>
- depth != 1
- ? arr. reduce (( a, v) => a. concat ( Array. isArray ( v) ? flattenDepth ( v, depth - 1 ) : v), [])
- : arr. reduce (( a, v) => a. concat ( v), []);
-Show examples flattenDepth ([ 1 , [ 2 ], 3 , 4 ]);
📋 Copy to clipboard forEachRight Executes a provided function once for each array element, starting from the array's last element.
Use Array.slice(0) to clone the given array, Array.reverse() to reverse it and Array.forEach() to iterate over the reversed array.
const forEachRight = ( arr, callback) =>
arr
. slice ( 0 )
@@ -1175,6 +1170,7 @@ Logs: {
+
const newPost = {
"userId" : 1 ,
"id" : 1337 ,
diff --git a/snippets/httpPost.md b/snippets/httpPost.md
index 7432560a7..55d29a095 100644
--- a/snippets/httpPost.md
+++ b/snippets/httpPost.md
@@ -29,6 +29,7 @@ const httpPost = (url, callback, data = null, err = console.error) => {
+
const newPost = {
"userId": 1,
"id": 1337,
diff --git a/tag_database b/tag_database
index ce9bf0ad2..bfbd0adbb 100644
--- a/tag_database
+++ b/tag_database
@@ -44,7 +44,6 @@ factorial:math,recursion
fibonacci:math,array
filterNonUnique:array
flatten:array
-flattenDepth:array,recursion
flip:adapter,function
forEachRight:array,function
formatDuration:date,math,string,utility