Creates a function that accepts up to n arguments, ignoring any additional arguments.
Call the provided function, fn, with up to n arguments, using Array.slice(0,n) and the spread operator (...).
const ary = ( fn, n) => ( ... args) => fn ( ... args. slice ( 0 , n));
+ } 30 seconds of code Curated collection of useful JavaScript snippets that you can understand in 30 seconds or less. Search for snippet...
Adapter ary call collectInto flip over overArgs pipeAsyncFunctions pipeFunctions promisify rearg spreadOver unary Array chunk compact countBy countOccurrences deepFlatten difference differenceBy differenceWith drop dropRight dropRightWhile dropWhile everyNth filterNonUnique findLast findLastIndex flatten forEachRight groupBy head indexOfAll initial initialize2DArray initializeArrayWithRange initializeArrayWithRangeRight initializeArrayWithValues intersection intersectionBy intersectionWith isSorted join last longestItem mapObject maxN minN nthElement partition pull pullAtIndex pullAtValue pullBy reducedFilter reduceSuccessive reduceWhich remove sample sampleSize shuffle similarity sortedIndex sortedIndexBy sortedLastIndex sortedLastIndexBy symmetricDifference symmetricDifferenceBy symmetricDifferenceWith tail take takeRight takeRightWhile takeWhile union unionBy unionWith uniqueElements unzip unzipWith without xProd zip zipObject zipWith Browser arrayToHtmlList bottomVisible copyToClipboard createElement createEventHub currentURL detectDeviceType elementIsVisibleInViewport getScrollPosition getStyle hasClass hashBrowser hide httpsRedirect observeMutations off on onUserInputChange redirect runAsync scrollToTop setStyle show toggleClass UUIDGeneratorBrowser Date formatDuration getColonTimeFromDate getDaysDiffBetweenDates getMeridiemSuffixOfInteger tomorrow Function attempt bind bindKey chainAsync compose composeRight curry debounce defer delay functionName memoize negate once partial partialRight runPromisesInSeries sleep throttle times unfold Math average averageBy clampNumber digitize distance elo factorial fibonacci gcd geometricProgression hammingDistance inRange isDivisible isEven isPrime lcm luhnCheck maxBy median minBy percentile powerset primes randomIntArrayInRange randomIntegerInRange randomNumberInRange round sdbm standardDeviation sum sumBy sumPower toSafeInteger Node atob btoa colorize hasFlags hashNode isTravisCI JSONToFile readFileLines untildify UUIDGeneratorNode Object bindAll deepClone defaults equals findKey findLastKey forOwn forOwnRight functions get invertKeyValues lowercaseKeys mapKeys mapValues matches matchesWith merge objectFromPairs objectToPairs omit omitBy orderBy pick pickBy shallowClone size transform truthCheckCollection String anagrams byteSize capitalize capitalizeEveryWord decapitalize escapeHTML escapeRegExp fromCamelCase isAbsoluteURL isLowerCase isUpperCase mask palindrome pluralize removeNonASCII reverseString sortCharactersInString splitLines stripHTMLTags toCamelCase toKebabCase toSnakeCase truncateString unescapeHTML URLJoin words Type getType is isArrayLike isBoolean isEmpty isFunction isNil isNull isNumber isObject isObjectLike isPlainObject isPrimitive isPromiseLike isString isSymbol isUndefined isValidJSON Utility castArray cloneRegExp coalesce coalesceFactory extendHex getURLParameters hexToRGB httpGet httpPost nthArg parseCookie prettyBytes randomHexColorCode RGBToHex serializeCookie timeTaken toCurrency toDecimalMark toOrdinalSuffix validateNumber yesNo Adapter ary Creates a function that accepts up to n arguments, ignoring any additional arguments.
Call the provided function, fn, with up to n arguments, using Array.slice(0,n) and the spread operator (...).
const ary = ( fn, n) => ( ... args) => fn ( ... args. slice ( 0 , n));
Show examples const firstTwoMax = ary ( Math. max, 2 );
[[ 2 , 6 , 'a' ], [ 8 , 4 , 6 ], [ 10 ]]. map ( x => firstTwoMax ( ... x));
📋 Copy to clipboard 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);
@@ -770,9 +770,19 @@ document. bodyShow examplesformatDuration ( 1001 );
formatDuration ( 34325055574 );
+📋 Copy to clipboard getColonTimeFromDate Returns a string of the form HH:MM:SS from a Date object.
Use Date.toString() and String.slice() to get the HH:MM:SS part of a given Date object.
const getColonTimeFromDate = date => date. toTimeString (). slice ( 0 , 8 );
+Show examples getColonTimeFromDate ( new Date ());
📋 Copy to clipboard getDaysDiffBetweenDates Returns the difference (in days) between two dates.
Calculate the difference (in days) between two Date objects.
const getDaysDiffBetweenDates = ( dateInitial, dateFinal) =>
( dateFinal - dateInitial) / ( 1000 * 3600 * 24 );
Show examples getDaysDiffBetweenDates ( new Date ( '2017-12-13' ), new Date ( '2017-12-22' ));
+📋 Copy to clipboard getMeridiemSuffixOfInteger Converts an integer to a suffixed string, adding am or pm based on its value.
Use the modulo operator (%) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.
const getMeridiemSuffixOfInteger = num =>
+ num === 0 || num === 24
+ ? 12 + 'am'
+ : num === 12 ? 12 + 'pm' : num < 12 ? num % 12 + 'am' : num % 12 + 'pm' ;
+Show examples getMeridiemSuffixOfInteger ( 0 );
+getMeridiemSuffixOfInteger ( 11 );
+getMeridiemSuffixOfInteger ( 13 );
+getMeridiemSuffixOfInteger ( 25 );
📋 Copy to clipboard tomorrow Results in a string representation of tomorrow's date. Use new Date() to get today's date, adding one day using Date.getDate() and Date.setDate(), and converting the Date object to a string.
const tomorrow = () => {
let t = new Date ();
t. setDate ( t. getDate () + 1 );
@@ -1875,14 +1885,4 @@ Logs: {
yesNo ( 'yes' );
yesNo ( 'No' );
yesNo ( 'Foo' , true );
-📋 Copy to clipboard Uncategorized getColonTimeFromDate Returns a string of the form HH:MM:SS from a Date object.
Use Date.toString() and String.slice() to get the HH:MM:SS part of a given Date object.
const getColonTimeFromDate = date => date. toTimeString (). slice ( 0 , 8 );
-Show examples getColonTimeFromDate ( new Date ());
-📋 Copy to clipboard getMeridiemSuffixOfInteger Converts an integer to a suffixed string, adding am or pm based on its value.
Use the modulo operator (%) and conditional checks to transform an integer to a stringified 12-hour format with meridiem suffix.
const getMeridiemSuffixOfInteger = num =>
- num === 0 || num === 24
- ? 12 + 'am'
- : num === 12 ? 12 + 'pm' : num < 12 ? num % 12 + 'am' : num % 12 + 'pm' ;
-Show examples getMeridiemSuffixOfInteger ( 0 );
-getMeridiemSuffixOfInteger ( 11 );
-getMeridiemSuffixOfInteger ( 13 );
-getMeridiemSuffixOfInteger ( 25 );
-📋 Copy to clipboard ↑