From 3900189a778fb228617e4eae7b7f067407b947c6 Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Wed, 14 Feb 2018 11:56:44 +0200 Subject: [PATCH 01/10] Add uncurry --- snippets/uncurry.md | 23 + tag_database | 1 + test/testlog | 1921 +++++++++++++++++----------------- test/uncurry/uncurry.js | 6 + test/uncurry/uncurry.test.js | 20 + 5 files changed, 1014 insertions(+), 957 deletions(-) create mode 100644 snippets/uncurry.md create mode 100644 test/uncurry/uncurry.js create mode 100644 test/uncurry/uncurry.test.js diff --git a/snippets/uncurry.md b/snippets/uncurry.md new file mode 100644 index 000000000..c5757e88d --- /dev/null +++ b/snippets/uncurry.md @@ -0,0 +1,23 @@ +### uncurry + +Uncurries a function up to depth `n`. + +Return a variadic function. +Use `Array.reduce()` on the provided arguments to call each subsequent curry level of the function. +If the `length` of the provided arguments is less than `n` throw an error. +Otherwise, call `fn` with the proper amount of arguments, using `Array.slice(0, n)`. +Omit the second argument, `n`, to uncurry up to depth `1`. + +```js +const uncurry = (fn, n = 1) => (...args) => { + const next = acc => args => args.reduce((x, y) => x(y), acc); + if (n > args.length) throw new RangeError('Arguments too few!'); + return next(fn)(args.slice(0, n)); +}; +``` + +```js +const add = x => y => z => x + y + z; +const uncurriedAdd = uncurry(add, 3); +uncurriedAdd(1, 2, 3); // 6 +``` diff --git a/tag_database b/tag_database index ab6f57af0..6459c8aae 100644 --- a/tag_database +++ b/tag_database @@ -252,6 +252,7 @@ transform:object,array truncateString:string truthCheckCollection:object,logic,array unary:adapter,function +uncurry:function unescapeHTML:string,browser unflattenObject:object,advanced unfold:function,array diff --git a/test/testlog b/test/testlog index 85ec8e717..9ffd675a9 100644 --- a/test/testlog +++ b/test/testlog @@ -1,1810 +1,1817 @@ -Test log for: Tue Feb 13 2018 20:22:09 GMT+0000 (UTC) +Test log for: Wed Feb 14 2018 11:56:24 GMT+0200 (GTB Standard Time) -> 30-seconds-of-code@0.0.1 test /home/travis/build/Chalarangelo/30-seconds-of-code +> 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code > tape test/**/*.test.js | tap-spec - Testing JSONToDate - - ✔ JSONToDate is a Function - - Testing JSONToFile - - ✔ JSONToFile is a Function - ✔ Tested on 09/02/2018 by @chalarangelo - - Testing RGBToHex - - ✔ RGBToHex is a Function - ✔ Converts the values of RGB components to a color code. - - Testing URLJoin - - ✔ URLJoin is a Function - ✔ Returns proper URL - ✔ Returns proper URL - - Testing UUIDGeneratorBrowser - - ✔ UUIDGeneratorBrowser is a Function - ✔ Tested 09/02/2018 by @chalarangelo - - Testing UUIDGeneratorNode - - ✔ UUIDGeneratorNode is a Function - ✔ Contains dashes in the proper places - ✔ Only contains hexadecimal digits - Testing anagrams - ✔ anagrams is a Function - ✔ Generates all anagrams of a string - ✔ Works for single-letter strings - ✔ Works for empty strings + √ anagrams is a Function + √ Generates all anagrams of a string + √ Works for single-letter strings + √ Works for empty strings Testing arrayToHtmlList - ✔ arrayToHtmlList is a Function + √ arrayToHtmlList is a Function Testing ary - ✔ ary is a Function - ✔ Discards arguments with index >=n + √ ary is a Function + √ Discards arguments with index >=n Testing atob - ✔ atob is a Function - ✔ atob("Zm9vYmFy") equals "foobar" - ✔ atob("Z") returns "" + √ atob is a Function + √ atob("Zm9vYmFy") equals "foobar" + √ atob("Z") returns "" Testing attempt - ✔ attempt is a Function - ✔ Returns a value - ✔ Returns an error + √ attempt is a Function + √ Returns a value + √ Returns an error Testing average - ✔ average is a Function - ✔ average(true) returns 0 - ✔ average(false) returns 1 - ✔ average(9, 1) returns 5 - ✔ average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 - ✔ average(1, 2, 3) returns 2 - ✔ average(null) returns 0 - ✔ average(1, 2, 3) returns NaN - ✔ average(String) returns NaN - ✔ average({ a: 123}) returns NaN - ✔ average([undefined, 0, string]) returns NaN - ✔ head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run + √ average is a Function + √ average(true) returns 0 + √ average(false) returns 1 + √ average(9, 1) returns 5 + √ average(153, 44, 55, 64, 71, 1122, 322774, 2232, 23423, 234, 3631) returns 32163.909090909092 + √ average(1, 2, 3) returns 2 + √ average(null) returns 0 + √ average(1, 2, 3) returns NaN + √ average(String) returns NaN + √ average({ a: 123}) returns NaN + √ average([undefined, 0, string]) returns NaN + √ head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run Testing averageBy - ✔ averageBy is a Function - ✔ Produces the right result with a function - ✔ Produces the right result with a property name + √ averageBy is a Function + √ Produces the right result with a function + √ Produces the right result with a property name Testing binarySearch - ✔ binarySearch is a Function - ✔ Finds item in array - ✔ Returns -1 when not found - ✔ Works with empty arrays - ✔ Works for one element arrays + √ binarySearch is a Function + √ Finds item in array + √ Returns -1 when not found + √ Works with empty arrays + √ Works for one element arrays Testing bind - ✔ bind is a Function - ✔ Binds to an object context + √ bind is a Function + √ Binds to an object context Testing bindAll - ✔ bindAll is a Function - ✔ Binds to an object context + √ bindAll is a Function + √ Binds to an object context Testing bindKey - ✔ bindKey is a Function - ✔ Binds function to an object context + √ bindKey is a Function + √ Binds function to an object context Testing bottomVisible - ✔ bottomVisible is a Function - ✔ Tested on 09/02/2018 by @chalarangelo + √ bottomVisible is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing btoa - ✔ btoa is a Function - ✔ btoa("foobar") equals "Zm9vYmFy" + √ btoa is a Function + √ btoa("foobar") equals "Zm9vYmFy" Testing byteSize - ✔ byteSize is a Function - ✔ Works for a single letter - ✔ Works for a common string - ✔ Works for emoji + √ byteSize is a Function + √ Works for a single letter + √ Works for a common string + √ Works for emoji Testing call - ✔ call is a Function - ✔ Calls function on given object + √ call is a Function + √ Calls function on given object Testing capitalize - ✔ capitalize is a Function - ✔ Capitalizes the first letter of a string - ✔ Capitalizes the first letter of a string - ✔ Works with characters - ✔ Works with single character words + √ capitalize is a Function + √ Capitalizes the first letter of a string + √ Capitalizes the first letter of a string + √ Works with characters + √ Works with single character words Testing capitalizeEveryWord - ✔ capitalizeEveryWord is a Function - ✔ Capitalizes the first letter of every word in a string - ✔ Works with characters - ✔ Works with one word string + √ capitalizeEveryWord is a Function + √ Capitalizes the first letter of every word in a string + √ Works with characters + √ Works with one word string Testing castArray - ✔ castArray is a Function - ✔ Works for single values - ✔ Works for arrays with one value - ✔ Works for arrays with multiple value - ✔ Works for strings - ✔ Works for objects + √ castArray is a Function + √ Works for single values + √ Works for arrays with one value + √ Works for arrays with multiple value + √ Works for strings + √ Works for objects Testing chainAsync - ✔ chainAsync is a Function + √ chainAsync is a Function Testing chunk - ✔ chunk is a Function - ✔ chunk([1, 2, 3, 4, 5], 2) returns [[1,2],[3,4],[5]] - ✔ chunk([]) returns [] - ✔ chunk(123) returns [] - ✔ chunk({ a: 123}) returns [] - ✔ chunk(string, 2) returns [ st, ri, ng ] - ✔ chunk() throws an error - ✔ chunk(undefined) throws an error - ✔ chunk(null) throws an error - ✔ chunk(This is a string, 2) takes less than 2s to run + √ chunk is a Function + √ chunk([1, 2, 3, 4, 5], 2) returns [[1,2],[3,4],[5]] + √ chunk([]) returns [] + √ chunk(123) returns [] + √ chunk({ a: 123}) returns [] + √ chunk(string, 2) returns [ st, ri, ng ] + √ chunk() throws an error + √ chunk(undefined) throws an error + √ chunk(null) throws an error + √ chunk(This is a string, 2) takes less than 2s to run Testing clampNumber - ✔ clampNumber is a Function - ✔ Clamps num within the inclusive range specified by the boundary values a and b + √ clampNumber is a Function + √ Clamps num within the inclusive range specified by the boundary values a and b Testing cleanObj - ✔ cleanObj is a Function - ✔ Removes any properties except the ones specified from a JSON object + √ cleanObj is a Function + √ Removes any properties except the ones specified from a JSON object Testing cloneRegExp - ✔ cloneRegExp is a Function - ✔ Clones regular expressions properly + √ cloneRegExp is a Function + √ Clones regular expressions properly Testing coalesce - ✔ coalesce is a Function - ✔ Returns the first non-null/undefined argument + √ coalesce is a Function + √ Returns the first non-null/undefined argument Testing coalesceFactory - ✔ coalesceFactory is a Function - ✔ Returns a customized coalesce function + √ coalesceFactory is a Function + √ Returns a customized coalesce function Testing collatz - ✔ collatz is a Function - ✔ When n is even, divide by 2 - ✔ When n is odd, times by 3 and add 1 - ✔ Eventually reaches 1 + √ collatz is a Function + √ When n is even, divide by 2 + √ When n is odd, times by 3 and add 1 + √ Eventually reaches 1 Testing collectInto - ✔ collectInto is a Function + √ collectInto is a Function Testing colorize - ✔ colorize is a Function - ✔ Tested on 09/02/2018 by @chalarangelo + √ colorize is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing compact - ✔ compact is a Function - ✔ Removes falsey values from an array + √ compact is a Function + √ Removes falsey values from an array Testing compose - ✔ compose is a Function - ✔ Performs right-to-left function composition + √ compose is a Function + √ Performs right-to-left function composition Testing composeRight - ✔ composeRight is a Function - ✔ Performs left-to-right function composition + √ composeRight is a Function + √ Performs left-to-right function composition Testing converge - ✔ converge is a Function - ✔ Produces the average of the array - ✔ Produces the strange concatenation + √ converge is a Function + √ Produces the average of the array + √ Produces the strange concatenation Testing copyToClipboard - ✔ copyToClipboard is a Function - ✔ Tested on 09/02/2018 by @chalarangelo + √ copyToClipboard is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing countBy - ✔ countBy is a Function - ✔ Works for functions - ✔ Works for property names + √ countBy is a Function + √ Works for functions + √ Works for property names Testing countOccurrences - ✔ countOccurrences is a Function - ✔ Counts the occurrences of a value in an array + √ countOccurrences is a Function + √ Counts the occurrences of a value in an array Testing countVowels - ✔ countVowels is a Function + √ countVowels is a Function Testing createElement - ✔ createElement is a Function + √ createElement is a Function Testing createEventHub - ✔ createEventHub is a Function + √ createEventHub is a Function Testing currentURL - ✔ currentURL is a Function + √ currentURL is a Function Testing curry - ✔ curry is a Function - ✔ curries a Math.pow - ✔ curries a Math.min + √ curry is a Function + √ curries a Math.pow + √ curries a Math.min Testing debounce - ✔ debounce is a Function + √ debounce is a Function Testing decapitalize - ✔ decapitalize is a Function - ✔ Works with default parameter - ✔ Works with second parameter set to true + √ decapitalize is a Function + √ Works with default parameter + √ Works with second parameter set to true Testing deepClone - ✔ deepClone is a Function - ✔ Shallow cloning works - ✔ Deep cloning works + √ deepClone is a Function + √ Shallow cloning works + √ Deep cloning works Testing deepFlatten - ✔ deepFlatten is a Function - ✔ Deep flattens an array + √ deepFlatten is a Function + √ Deep flattens an array Testing defaults - ✔ defaults is a Function + √ defaults is a Function Testing defer - ✔ defer is a Function + √ defer is a Function Testing delay - ✔ delay is a Function + √ delay is a Function Testing detectDeviceType - ✔ detectDeviceType is a Function - ✔ Tested on 09/02/2018 by @chalarangelo + √ detectDeviceType is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing difference - ✔ difference is a Function - ✔ Returns the difference between two arrays + √ difference is a Function + √ Returns the difference between two arrays Testing differenceBy - ✔ differenceBy is a Function - ✔ Works using a native function and numbers - ✔ Works with arrow function and objects + √ differenceBy is a Function + √ Works using a native function and numbers + √ Works with arrow function and objects Testing differenceWith - ✔ differenceWith is a Function - ✔ Filters out all values from an array + √ differenceWith is a Function + √ Filters out all values from an array Testing digitize - ✔ digitize is a Function - ✔ Converts a number to an array of digits + √ digitize is a Function + √ Converts a number to an array of digits Testing distance - ✔ distance is a Function - ✔ Calculates the distance between two points + √ distance is a Function + √ Calculates the distance between two points Testing drop - ✔ drop is a Function - ✔ Works without the last argument - ✔ Removes appropriate element count as specified - ✔ Empties array given a count greater than length + √ drop is a Function + √ Works without the last argument + √ Removes appropriate element count as specified + √ Empties array given a count greater than length Testing dropRight - ✔ dropRight is a Function - ✔ Returns a new array with n elements removed from the right - ✔ Returns a new array with n elements removed from the right - ✔ Returns a new array with n elements removed from the right + √ dropRight is a Function + √ Returns a new array with n elements removed from the right + √ Returns a new array with n elements removed from the right + √ Returns a new array with n elements removed from the right Testing dropRightWhile - ✔ dropRightWhile is a Function - ✔ Removes elements from the end of an array until the passed function returns true. + √ dropRightWhile is a Function + √ Removes elements from the end of an array until the passed function returns true. Testing dropWhile - ✔ dropWhile is a Function - ✔ Removes elements in an array until the passed function returns true. + √ dropWhile is a Function + √ Removes elements in an array until the passed function returns true. Testing elementIsVisibleInViewport - ✔ elementIsVisibleInViewport is a Function - ✔ Tested on 09/02/2018 by @chalarangelo + √ elementIsVisibleInViewport is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing elo - ✔ elo is a Function - ✔ Standard 1v1s - ✔ should be equivalent - ✔ 4 player FFA, all same rank + √ elo is a Function + √ Standard 1v1s + √ should be equivalent + √ 4 player FFA, all same rank Testing equals - ✔ equals is a Function - ✔ { a: [2, {e: 3}], b: [4], c: 'foo' } is equal to { a: [2, {e: 3}], b: [4], c: 'foo' } - ✔ [1,2,3] is equal to [1,2,3] - ✔ { a: [2, 3], b: [4] } is not equal to { a: [2, 3], b: [6] } - ✔ [1,2,3] is not equal to [1,2,4] - ✔ [1, 2, 3] should be equal to { 0: 1, 1: 2, 2: 3 }) - type is different, but their enumerable properties match. + √ equals is a Function + √ { a: [2, {e: 3}], b: [4], c: 'foo' } is equal to { a: [2, {e: 3}], b: [4], c: 'foo' } + √ [1,2,3] is equal to [1,2,3] + √ { a: [2, 3], b: [4] } is not equal to { a: [2, 3], b: [6] } + √ [1,2,3] is not equal to [1,2,4] + √ [1, 2, 3] should be equal to { 0: 1, 1: 2, 2: 3 }) - type is different, but their enumerable properties match. Testing escapeHTML - ✔ escapeHTML is a Function - ✔ Escapes a string for use in HTML + √ escapeHTML is a Function + √ Escapes a string for use in HTML Testing escapeRegExp - ✔ escapeRegExp is a Function - ✔ Escapes a string to use in a regular expression + √ escapeRegExp is a Function + √ Escapes a string to use in a regular expression Testing everyNth - ✔ everyNth is a Function - ✔ Returns every nth element in an array + √ everyNth is a Function + √ Returns every nth element in an array Testing extendHex - ✔ extendHex is a Function - ✔ Extends a 3-digit color code to a 6-digit color code - ✔ Extends a 3-digit color code to a 6-digit color code + √ extendHex is a Function + √ Extends a 3-digit color code to a 6-digit color code + √ Extends a 3-digit color code to a 6-digit color code Testing factorial - ✔ factorial is a Function - ✔ Calculates the factorial of 720 - ✔ Calculates the factorial of 0 - ✔ Calculates the factorial of 1 - ✔ Calculates the factorial of 4 - ✔ Calculates the factorial of 10 + √ factorial is a Function + √ Calculates the factorial of 720 + √ Calculates the factorial of 0 + √ Calculates the factorial of 1 + √ Calculates the factorial of 4 + √ Calculates the factorial of 10 Testing factors - ✔ factors is a Function + √ factors is a Function Testing fibonacci - ✔ fibonacci is a Function - ✔ Generates an array, containing the Fibonacci sequence + √ fibonacci is a Function + √ Generates an array, containing the Fibonacci sequence Testing fibonacciCountUntilNum - ✔ fibonacciCountUntilNum is a Function + √ fibonacciCountUntilNum is a Function Testing fibonacciUntilNum - ✔ fibonacciUntilNum is a Function + √ fibonacciUntilNum is a Function Testing filterNonUnique - ✔ filterNonUnique is a Function - ✔ Filters out the non-unique values in an array + √ filterNonUnique is a Function + √ Filters out the non-unique values in an array Testing findKey - ✔ findKey is a Function - ✔ Returns the appropriate key + √ findKey is a Function + √ Returns the appropriate key Testing findLast - ✔ findLast is a Function - ✔ Finds last element for which the given function returns true + √ findLast is a Function + √ Finds last element for which the given function returns true Testing findLastIndex - ✔ findLastIndex is a Function - ✔ Finds last index for which the given function returns true + √ findLastIndex is a Function + √ Finds last index for which the given function returns true Testing findLastKey - ✔ findLastKey is a Function - ✔ Returns the appropriate key + √ findLastKey is a Function + √ Returns the appropriate key Testing flatten - ✔ flatten is a Function - ✔ Flattens an array - ✔ Flattens an array + √ flatten is a Function + √ Flattens an array + √ Flattens an array Testing flattenObject - ✔ flattenObject is a Function - ✔ Flattens an object with the paths for keys - ✔ Works with arrays + √ flattenObject is a Function + √ Flattens an object with the paths for keys + √ Works with arrays Testing flip - ✔ flip is a Function - ✔ Flips argument order + √ flip is a Function + √ Flips argument order Testing forEachRight - ✔ forEachRight is a Function - ✔ Iterates over the array in reverse - - Testing forOwn - - ✔ forOwn is a Function - ✔ Iterates over an element's key-value pairs - - Testing forOwnRight - - ✔ forOwnRight is a Function - ✔ Iterates over an element's key-value pairs in reverse + √ forEachRight is a Function + √ Iterates over the array in reverse Testing formatDuration - ✔ formatDuration is a Function - ✔ Returns the human readable format of the given number of milliseconds - ✔ Returns the human readable format of the given number of milliseconds + √ formatDuration is a Function + √ Returns the human readable format of the given number of milliseconds + √ Returns the human readable format of the given number of milliseconds + + Testing forOwn + + √ forOwn is a Function + √ Iterates over an element's key-value pairs + + Testing forOwnRight + + √ forOwnRight is a Function + √ Iterates over an element's key-value pairs in reverse Testing fromCamelCase - ✔ fromCamelCase is a Function - ✔ Converts a string from camelcase - ✔ Converts a string from camelcase - ✔ Converts a string from camelcase + √ fromCamelCase is a Function + √ Converts a string from camelcase + √ Converts a string from camelcase + √ Converts a string from camelcase Testing functionName - ✔ functionName is a Function - ✔ Works for native functions - ✔ Works for functions - ✔ Works for arrow functions + √ functionName is a Function + √ Works for native functions + √ Works for functions + √ Works for arrow functions Testing functions - ✔ functions is a Function - ✔ Returns own methods - ✔ Returns own and inherited methods + √ functions is a Function + √ Returns own methods + √ Returns own and inherited methods Testing gcd - ✔ gcd is a Function - ✔ Calculates the greatest common divisor between two or more numbers/arrays - ✔ Calculates the greatest common divisor between two or more numbers/arrays + √ gcd is a Function + √ Calculates the greatest common divisor between two or more numbers/arrays + √ Calculates the greatest common divisor between two or more numbers/arrays Testing geometricProgression - ✔ geometricProgression is a Function - ✔ Initializes an array containing the numbers in the specified range - ✔ Initializes an array containing the numbers in the specified range - ✔ Initializes an array containing the numbers in the specified range + √ geometricProgression is a Function + √ Initializes an array containing the numbers in the specified range + √ Initializes an array containing the numbers in the specified range + √ Initializes an array containing the numbers in the specified range Testing get - ✔ get is a Function - ✔ Retrieve a property indicated by the selector from an object. + √ get is a Function + √ Retrieve a property indicated by the selector from an object. Testing getColonTimeFromDate - ✔ getColonTimeFromDate is a Function + √ getColonTimeFromDate is a Function Testing getDaysDiffBetweenDates - ✔ getDaysDiffBetweenDates is a Function - ✔ Returns the difference in days between two dates + √ getDaysDiffBetweenDates is a Function + √ Returns the difference in days between two dates Testing getMeridiemSuffixOfInteger - ✔ getMeridiemSuffixOfInteger is a Function + √ getMeridiemSuffixOfInteger is a Function Testing getScrollPosition - ✔ getScrollPosition is a Function + √ getScrollPosition is a Function Testing getStyle - ✔ getStyle is a Function + √ getStyle is a Function Testing getType - ✔ getType is a Function - ✔ Returns the native type of a value + √ getType is a Function + √ Returns the native type of a value Testing getURLParameters - ✔ getURLParameters is a Function - ✔ Returns an object containing the parameters of the current URL + √ getURLParameters is a Function + √ Returns an object containing the parameters of the current URL Testing groupBy - ✔ groupBy is a Function - ✔ Groups the elements of an array based on the given function - ✔ Groups the elements of an array based on the given function + √ groupBy is a Function + √ Groups the elements of an array based on the given function + √ Groups the elements of an array based on the given function Testing hammingDistance - ✔ hammingDistance is a Function - ✔ retuns hamming disance between 2 values + √ hammingDistance is a Function + √ retuns hamming disance between 2 values Testing hasClass - ✔ hasClass is a Function + √ hasClass is a Function Testing hasFlags - ✔ hasFlags is a Function + √ hasFlags is a Function Testing hashBrowser - ✔ hashBrowser is a Function + √ hashBrowser is a Function Testing hashNode - ✔ hashNode is a Function + √ hashNode is a Function Testing head - ✔ head is a Function - ✔ head({ a: 1234}) returns undefined - ✔ head([1, 2, 3]) returns 1 - ✔ head({ 0: false}) returns false - ✔ head(String) returns S - ✔ head(null) throws an Error - ✔ head(undefined) throws an Error - ✔ head() throws an Error - ✔ head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run + √ head is a Function + √ head({ a: 1234}) returns undefined + √ head([1, 2, 3]) returns 1 + √ head({ 0: false}) returns false + √ head(String) returns S + √ head(null) throws an Error + √ head(undefined) throws an Error + √ head() throws an Error + √ head([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run Testing hexToRGB - ✔ hexToRGB is a Function - ✔ Converts a color code to a rgb() or rgba() string - ✔ Converts a color code to a rgb() or rgba() string - ✔ Converts a color code to a rgb() or rgba() string + √ hexToRGB is a Function + √ Converts a color code to a rgb() or rgba() string + √ Converts a color code to a rgb() or rgba() string + √ Converts a color code to a rgb() or rgba() string Testing hide - ✔ hide is a Function + √ hide is a Function Testing howManyTimes - ✔ howManyTimes is a Function + √ howManyTimes is a Function Testing httpDelete - ✔ httpDelete is a Function + √ httpDelete is a Function Testing httpGet - ✔ httpGet is a Function + √ httpGet is a Function Testing httpPost - ✔ httpPost is a Function + √ httpPost is a Function Testing httpPut - ✔ httpPut is a Function + √ httpPut is a Function Testing httpsRedirect - ✔ httpsRedirect is a Function - ✔ Tested on 09/02/2018 by @chalarangelo - - Testing inRange - - ✔ inRange is a Function - ✔ The given number falls within the given range - ✔ The given number falls within the given range - ✔ The given number does not falls within the given range - ✔ The given number does not falls within the given range + √ httpsRedirect is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing indexOfAll - ✔ indexOfAll is a Function - ✔ Returns all indices of val in an array - ✔ Returns all indices of val in an array + √ indexOfAll is a Function + √ Returns all indices of val in an array + √ Returns all indices of val in an array Testing initial - ✔ initial is a Function - ✔ Returns all the elements of an array except the last one + √ initial is a Function + √ Returns all the elements of an array except the last one Testing initialize2DArray - ✔ initialize2DArray is a Function - ✔ Initializes a 2D array of given width and height and value + √ initialize2DArray is a Function + √ Initializes a 2D array of given width and height and value Testing initializeArrayWithRange - ✔ initializeArrayWithRange is a Function - ✔ Initializes an array containing the numbers in the specified range + √ initializeArrayWithRange is a Function + √ Initializes an array containing the numbers in the specified range Testing initializeArrayWithRangeRight - ✔ initializeArrayWithRangeRight is a Function + √ initializeArrayWithRangeRight is a Function Testing initializeArrayWithValues - ✔ initializeArrayWithValues is a Function - ✔ Initializes and fills an array with the specified values + √ initializeArrayWithValues is a Function + √ Initializes and fills an array with the specified values + + Testing inRange + + √ inRange is a Function + √ The given number falls within the given range + √ The given number falls within the given range + √ The given number does not falls within the given range + √ The given number does not falls within the given range Testing intersection - ✔ intersection is a Function - ✔ Returns a list of elements that exist in both arrays + √ intersection is a Function + √ Returns a list of elements that exist in both arrays Testing intersectionBy - ✔ intersectionBy is a Function - ✔ Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both + √ intersectionBy is a Function + √ Returns a list of elements that exist in both arrays, after applying the provided function to each array element of both Testing intersectionWith - ✔ intersectionWith is a Function - ✔ Returns a list of elements that exist in both arrays, using a provided comparator function + √ intersectionWith is a Function + √ Returns a list of elements that exist in both arrays, using a provided comparator function Testing invertKeyValues - ✔ invertKeyValues is a Function - ✔ invertKeyValues({ a: 1, b: 2, c: 1 }) returns { 1: [ 'a', 'c' ], 2: [ 'b' ] } - ✔ invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value) returns { group1: [ 'a', 'c' ], group2: [ 'b' ] } + √ invertKeyValues is a Function + √ invertKeyValues({ a: 1, b: 2, c: 1 }) returns { 1: [ 'a', 'c' ], 2: [ 'b' ] } + √ invertKeyValues({ a: 1, b: 2, c: 1 }, value => 'group' + value) returns { group1: [ 'a', 'c' ], group2: [ 'b' ] } Testing is - ✔ is is a Function - ✔ Works for arrays with data - ✔ Works for empty arrays - ✔ Works for arrays, not objects - ✔ Works for objects - ✔ Works for maps - ✔ Works for regular expressions - ✔ Works for sets - ✔ Works for weak maps - ✔ Works for weak sets - ✔ Works for strings - returns false for primitive - ✔ Works for strings - returns true when using constructor - ✔ Works for numbers - returns false for primitive - ✔ Works for numbers - returns true when using constructor - ✔ Works for booleans - returns false for primitive - ✔ Works for booleans - returns true when using constructor - ✔ Works for functions + √ is is a Function + √ Works for arrays with data + √ Works for empty arrays + √ Works for arrays, not objects + √ Works for objects + √ Works for maps + √ Works for regular expressions + √ Works for sets + √ Works for weak maps + √ Works for weak sets + √ Works for strings - returns false for primitive + √ Works for strings - returns true when using constructor + √ Works for numbers - returns false for primitive + √ Works for numbers - returns true when using constructor + √ Works for booleans - returns false for primitive + √ Works for booleans - returns true when using constructor + √ Works for functions Testing isAbsoluteURL - ✔ isAbsoluteURL is a Function - ✔ Given string is an absolute URL - ✔ Given string is an absolute URL - ✔ Given string is not an absolute URL + √ isAbsoluteURL is a Function + √ Given string is an absolute URL + √ Given string is an absolute URL + √ Given string is not an absolute URL Testing isArmstrongNumber - ✔ isArmstrongNumber is a Function + √ isArmstrongNumber is a Function Testing isArray - ✔ isArray is a Function - ✔ passed value is an array - ✔ passed value is not an array + √ isArray is a Function + √ passed value is an array + √ passed value is not an array Testing isArrayBuffer - ✔ isArrayBuffer is a Function + √ isArrayBuffer is a Function Testing isArrayLike - ✔ isArrayLike is a Function - ✔ Returns true for a string - ✔ Returns true for an array - ✔ Returns false for null + √ isArrayLike is a Function + √ Returns true for a string + √ Returns true for an array + √ Returns false for null Testing isBoolean - ✔ isBoolean is a Function - ✔ passed value is not a boolean - ✔ passed value is not a boolean + √ isBoolean is a Function + √ passed value is not a boolean + √ passed value is not a boolean Testing isDivisible - ✔ isDivisible is a Function - ✔ The number 6 is divisible by 3 + √ isDivisible is a Function + √ The number 6 is divisible by 3 Testing isEmpty - ✔ isEmpty is a Function - ✔ Returns true for empty Map - ✔ Returns true for empty Set - ✔ Returns true for empty array - ✔ Returns true for empty object - ✔ Returns true for empty string - ✔ Returns false for non-empty array - ✔ Returns false for non-empty object - ✔ Returns false for non-empty string - ✔ Returns true - type is not considered a collection - ✔ Returns true - type is not considered a collection + √ isEmpty is a Function + √ Returns true for empty Map + √ Returns true for empty Set + √ Returns true for empty array + √ Returns true for empty object + √ Returns true for empty string + √ Returns false for non-empty array + √ Returns false for non-empty object + √ Returns false for non-empty string + √ Returns true - type is not considered a collection + √ Returns true - type is not considered a collection Testing isEven - ✔ isEven is a Function - ✔ 4 is even number - ✔ undefined + √ isEven is a Function + √ 4 is even number + √ undefined Testing isFunction - ✔ isFunction is a Function - ✔ passed value is a function - ✔ passed value is not a function + √ isFunction is a Function + √ passed value is a function + √ passed value is not a function Testing isLowerCase - ✔ isLowerCase is a Function - ✔ passed string is a lowercase - ✔ passed string is a lowercase - ✔ passed value is not a lowercase + √ isLowerCase is a Function + √ passed string is a lowercase + √ passed string is a lowercase + √ passed value is not a lowercase Testing isMap - ✔ isMap is a Function + √ isMap is a Function Testing isNil - ✔ isNil is a Function - ✔ Returns true for null - ✔ Returns true for undefined - ✔ Returns false for an empty string + √ isNil is a Function + √ Returns true for null + √ Returns true for undefined + √ Returns false for an empty string Testing isNull - ✔ isNull is a Function - ✔ passed argument is a null - ✔ passed argument is a null + √ isNull is a Function + √ passed argument is a null + √ passed argument is a null Testing isNumber - ✔ isNumber is a Function - ✔ passed argument is a number - ✔ passed argument is not a number + √ isNumber is a Function + √ passed argument is a number + √ passed argument is not a number Testing isObject - ✔ isObject is a Function - ✔ isObject([1, 2, 3, 4]) is a object - ✔ isObject([]) is a object - ✔ isObject({ a:1 }) is a object - ✔ isObject(true) is not a object + √ isObject is a Function + √ isObject([1, 2, 3, 4]) is a object + √ isObject([]) is a object + √ isObject({ a:1 }) is a object + √ isObject(true) is not a object Testing isObjectLike - ✔ isObjectLike is a Function - ✔ Returns true for an object - ✔ Returns true for an array - ✔ Returns false for a function - ✔ Returns false for null + √ isObjectLike is a Function + √ Returns true for an object + √ Returns true for an array + √ Returns false for a function + √ Returns false for null Testing isPlainObject - ✔ isPlainObject is a Function - ✔ Returns true for a plain object - ✔ Returns false for a Map (example of non-plain object) + √ isPlainObject is a Function + √ Returns true for a plain object + √ Returns false for a Map (example of non-plain object) Testing isPrime - ✔ isPrime is a Function - ✔ passed number is a prime + √ isPrime is a Function + √ passed number is a prime Testing isPrimitive - ✔ isPrimitive is a Function - ✔ isPrimitive(null) is primitive - ✔ isPrimitive(undefined) is primitive - ✔ isPrimitive(string) is primitive - ✔ isPrimitive(true) is primitive - ✔ isPrimitive(50) is primitive - ✔ isPrimitive('Hello') is primitive - ✔ isPrimitive(false) is primitive - ✔ isPrimitive(Symbol()) is primitive - ✔ isPrimitive([1, 2, 3]) is not primitive - ✔ isPrimitive({ a: 123 }) is not primitive - ✔ isPrimitive({ a: 123 }) takes less than 2s to run + √ isPrimitive is a Function + √ isPrimitive(null) is primitive + √ isPrimitive(undefined) is primitive + √ isPrimitive(string) is primitive + √ isPrimitive(true) is primitive + √ isPrimitive(50) is primitive + √ isPrimitive('Hello') is primitive + √ isPrimitive(false) is primitive + √ isPrimitive(Symbol()) is primitive + √ isPrimitive([1, 2, 3]) is not primitive + √ isPrimitive({ a: 123 }) is not primitive + √ isPrimitive({ a: 123 }) takes less than 2s to run Testing isPromiseLike - ✔ isPromiseLike is a Function - ✔ Returns true for a promise-like object - ✔ Returns false for null - ✔ Returns false for an empty object + √ isPromiseLike is a Function + √ Returns true for a promise-like object + √ Returns false for null + √ Returns false for an empty object Testing isRegExp - ✔ isRegExp is a Function + √ isRegExp is a Function Testing isSet - ✔ isSet is a Function + √ isSet is a Function Testing isSorted - ✔ isSorted is a Function - ✔ Array is sorted in ascending order - ✔ Array is sorted in descending order - ✔ Array is not sorted, direction changed in array + √ isSorted is a Function + √ Array is sorted in ascending order + √ Array is sorted in descending order + √ Array is not sorted, direction changed in array Testing isString - ✔ isString is a Function - ✔ foo is a string - ✔ "10" is a string - ✔ Empty string is a string - ✔ 10 is not a string - ✔ true is not string + √ isString is a Function + √ foo is a string + √ "10" is a string + √ Empty string is a string + √ 10 is not a string + √ true is not string Testing isSymbol - ✔ isSymbol is a Function - ✔ Checks if the given argument is a symbol + √ isSymbol is a Function + √ Checks if the given argument is a symbol Testing isTravisCI - ✔ isTravisCI is a Function - ✔ Running on Travis, correctly evaluates + √ isTravisCI is a Function + √ Not running on Travis, correctly evaluates Testing isTypedArray - ✔ isTypedArray is a Function + √ isTypedArray is a Function Testing isUndefined - ✔ isUndefined is a Function - ✔ Returns true for undefined + √ isUndefined is a Function + √ Returns true for undefined Testing isUpperCase - ✔ isUpperCase is a Function - ✔ ABC is all upper case - ✔ abc is not all upper case - ✔ A3@$ is all uppercase + √ isUpperCase is a Function + √ ABC is all upper case + √ abc is not all upper case + √ A3@$ is all uppercase Testing isValidJSON - ✔ isValidJSON is a Function - ✔ {"name":"Adam","age":20} is a valid JSON - ✔ {"name":"Adam",age:"20"} is not a valid JSON - ✔ null is a valid JSON + √ isValidJSON is a Function + √ {"name":"Adam","age":20} is a valid JSON + √ {"name":"Adam",age:"20"} is not a valid JSON + √ null is a valid JSON Testing isWeakMap - ✔ isWeakMap is a Function + √ isWeakMap is a Function Testing isWeakSet - ✔ isWeakSet is a Function + √ isWeakSet is a Function Testing join - ✔ join is a Function - ✔ Joins all elements of an array into a string and returns this string - ✔ Joins all elements of an array into a string and returns this string - ✔ Joins all elements of an array into a string and returns this string + √ join is a Function + √ Joins all elements of an array into a string and returns this string + √ Joins all elements of an array into a string and returns this string + √ Joins all elements of an array into a string and returns this string + + Testing JSONToDate + + √ JSONToDate is a Function + + Testing JSONToFile + + √ JSONToFile is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing last - ✔ last is a Function - ✔ last({ a: 1234}) returns undefined - ✔ last([1, 2, 3]) returns 3 - ✔ last({ 0: false}) returns undefined - ✔ last(String) returns g - ✔ last(null) throws an Error - ✔ last(undefined) throws an Error - ✔ last() throws an Error - ✔ last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run + √ last is a Function + √ last({ a: 1234}) returns undefined + √ last([1, 2, 3]) returns 3 + √ last({ 0: false}) returns undefined + √ last(String) returns g + √ last(null) throws an Error + √ last(undefined) throws an Error + √ last() throws an Error + √ last([1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 1122, 32124, 23232]) takes less than 2s to run Testing lcm - ✔ lcm is a Function - ✔ Returns the least common multiple of two or more numbers. - ✔ Returns the least common multiple of two or more numbers. + √ lcm is a Function + √ Returns the least common multiple of two or more numbers. + √ Returns the least common multiple of two or more numbers. Testing longestItem - ✔ longestItem is a Function - ✔ Returns the longest object + √ longestItem is a Function + √ Returns the longest object Testing lowercaseKeys - ✔ lowercaseKeys is a Function - ✔ Lowercases object keys - ✔ Does not mutate original object + √ lowercaseKeys is a Function + √ Lowercases object keys + √ Does not mutate original object Testing luhnCheck - ✔ luhnCheck is a Function - ✔ validates identification number - ✔ validates identification number - ✔ validates identification number + √ luhnCheck is a Function + √ validates identification number + √ validates identification number + √ validates identification number Testing mapKeys - ✔ mapKeys is a Function - ✔ Maps keys + √ mapKeys is a Function + √ Maps keys Testing mapObject - ✔ mapObject is a Function - ✔ mapObject([1, 2, 3], a => a * a) returns { 1: 1, 2: 4, 3: 9 } - ✔ mapObject([1, 2, 3, 4], (a, b) => b - a) returns { 1: -1, 2: -1, 3: -1, 4: -1 } - ✔ mapObject([1, 2, 3, 4], (a, b) => a - b) returns { 1: 1, 2: 1, 3: 1, 4: 1 } + √ mapObject is a Function + √ mapObject([1, 2, 3], a => a * a) returns { 1: 1, 2: 4, 3: 9 } + √ mapObject([1, 2, 3, 4], (a, b) => b - a) returns { 1: -1, 2: -1, 3: -1, 4: -1 } + √ mapObject([1, 2, 3, 4], (a, b) => a - b) returns { 1: 1, 2: 1, 3: 1, 4: 1 } Testing mapValues - ✔ mapValues is a Function - ✔ Maps values + √ mapValues is a Function + √ Maps values Testing mask - ✔ mask is a Function - ✔ Replaces all but the last num of characters with the specified mask character - ✔ Replaces all but the last num of characters with the specified mask character - ✔ Replaces all but the last num of characters with the specified mask character + √ mask is a Function + √ Replaces all but the last num of characters with the specified mask character + √ Replaces all but the last num of characters with the specified mask character + √ Replaces all but the last num of characters with the specified mask character Testing matches - ✔ matches is a Function - ✔ Matches returns true for two similar objects - ✔ Matches returns false for two non-similar objects + √ matches is a Function + √ Matches returns true for two similar objects + √ Matches returns false for two non-similar objects Testing matchesWith - ✔ matchesWith is a Function - ✔ Returns true for two objects with similar values, based on the provided function + √ matchesWith is a Function + √ Returns true for two objects with similar values, based on the provided function Testing maxBy - ✔ maxBy is a Function - ✔ Produces the right result with a function - ✔ Produces the right result with a property name + √ maxBy is a Function + √ Produces the right result with a function + √ Produces the right result with a property name Testing maxN - ✔ maxN is a Function - ✔ Returns the n maximum elements from the provided array - ✔ Returns the n maximum elements from the provided array + √ maxN is a Function + √ Returns the n maximum elements from the provided array + √ Returns the n maximum elements from the provided array Testing median - ✔ median is a Function - ✔ Returns the median of an array of numbers - ✔ Returns the median of an array of numbers + √ median is a Function + √ Returns the median of an array of numbers + √ Returns the median of an array of numbers Testing memoize - ✔ memoize is a Function - ✔ Function works properly - ✔ Function works properly - ✔ Cache stores values + √ memoize is a Function + √ Function works properly + √ Function works properly + √ Cache stores values Testing merge - ✔ merge is a Function - ✔ Merges two objects + √ merge is a Function + √ Merges two objects Testing minBy - ✔ minBy is a Function - ✔ Produces the right result with a function - ✔ Produces the right result with a property name + √ minBy is a Function + √ Produces the right result with a function + √ Produces the right result with a property name Testing minN - ✔ minN is a Function - ✔ Returns the n minimum elements from the provided array - ✔ Returns the n minimum elements from the provided array + √ minN is a Function + √ Returns the n minimum elements from the provided array + √ Returns the n minimum elements from the provided array Testing negate - ✔ negate is a Function - ✔ Negates a predicate function + √ negate is a Function + √ Negates a predicate function Testing nthArg - ✔ nthArg is a Function - ✔ Returns the nth argument - ✔ Returns undefined if arguments too few - ✔ Works for negative values + √ nthArg is a Function + √ Returns the nth argument + √ Returns undefined if arguments too few + √ Works for negative values Testing nthElement - ✔ nthElement is a Function - ✔ Returns the nth element of an array. - ✔ Returns the nth element of an array. + √ nthElement is a Function + √ Returns the nth element of an array. + √ Returns the nth element of an array. Testing objectFromPairs - ✔ objectFromPairs is a Function - ✔ Creates an object from the given key-value pairs. + √ objectFromPairs is a Function + √ Creates an object from the given key-value pairs. Testing objectToPairs - ✔ objectToPairs is a Function - ✔ Creates an array of key-value pair arrays from an object. + √ objectToPairs is a Function + √ Creates an array of key-value pair arrays from an object. Testing observeMutations - ✔ observeMutations is a Function - ✔ Tested on 09/02/2018 by @chalarangelo + √ observeMutations is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing off - ✔ off is a Function + √ off is a Function Testing omit - ✔ omit is a Function - ✔ Omits the key-value pairs corresponding to the given keys from an object + √ omit is a Function + √ Omits the key-value pairs corresponding to the given keys from an object Testing omitBy - ✔ omitBy is a Function - ✔ Creates an object composed of the properties the given function returns falsey for + √ omitBy is a Function + √ Creates an object composed of the properties the given function returns falsey for Testing on - ✔ on is a Function - - Testing onUserInputChange - - ✔ onUserInputChange is a Function + √ on is a Function Testing once - ✔ once is a Function + √ once is a Function + + Testing onUserInputChange + + √ onUserInputChange is a Function Testing orderBy - ✔ orderBy is a Function - ✔ Returns a sorted array of objects ordered by properties and orders. - ✔ Returns a sorted array of objects ordered by properties and orders. + √ orderBy is a Function + √ Returns a sorted array of objects ordered by properties and orders. + √ Returns a sorted array of objects ordered by properties and orders. Testing over - ✔ over is a Function - ✔ Applies given functions over multiple arguments + √ over is a Function + √ Applies given functions over multiple arguments Testing overArgs - ✔ overArgs is a Function - ✔ Invokes the provided function with its arguments transformed + √ overArgs is a Function + √ Invokes the provided function with its arguments transformed Testing palindrome - ✔ palindrome is a Function - ✔ Given string is a palindrome - ✔ Given string is not a palindrome + √ palindrome is a Function + √ Given string is a palindrome + √ Given string is not a palindrome Testing parseCookie - ✔ parseCookie is a Function - ✔ Parses the cookie + √ parseCookie is a Function + √ Parses the cookie Testing partial - ✔ partial is a Function - ✔ Prepends arguments + √ partial is a Function + √ Prepends arguments Testing partialRight - ✔ partialRight is a Function - ✔ Appends arguments + √ partialRight is a Function + √ Appends arguments Testing partition - ✔ partition is a Function - ✔ Groups the elements into two arrays, depending on the provided function's truthiness for each element. + √ partition is a Function + √ Groups the elements into two arrays, depending on the provided function's truthiness for each element. Testing percentile - ✔ percentile is a Function - ✔ Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value. + √ percentile is a Function + √ Uses the percentile formula to calculate how many numbers in the given array are less or equal to the given value. Testing pick - ✔ pick is a Function - ✔ Picks the key-value pairs corresponding to the given keys from an object. + √ pick is a Function + √ Picks the key-value pairs corresponding to the given keys from an object. Testing pickBy - ✔ pickBy is a Function - ✔ Creates an object composed of the properties the given function returns truthy for. + √ pickBy is a Function + √ Creates an object composed of the properties the given function returns truthy for. Testing pipeAsyncFunctions - ✔ pipeAsyncFunctions is a Function - ✔ Produces the appropriate hash - ✔ pipeAsyncFunctions result should be 15 + √ pipeAsyncFunctions is a Function + √ Produces the appropriate hash + √ pipeAsyncFunctions result should be 15 Testing pipeFunctions - ✔ pipeFunctions is a Function - ✔ Performs left-to-right function composition + √ pipeFunctions is a Function + √ Performs left-to-right function composition Testing pluralize - ✔ pluralize is a Function - ✔ Produces the plural of the word - ✔ Produces the singular of the word - ✔ Produces the plural of the word - ✔ Prodices the defined plural of the word - ✔ Works with a dictionary + √ pluralize is a Function + √ Produces the plural of the word + √ Produces the singular of the word + √ Produces the plural of the word + √ Prodices the defined plural of the word + √ Works with a dictionary Testing powerset - ✔ powerset is a Function - ✔ Returns the powerset of a given array of numbers. + √ powerset is a Function + √ Returns the powerset of a given array of numbers. Testing prettyBytes - ✔ prettyBytes is a Function - ✔ Converts a number in bytes to a human-readable string. - ✔ Converts a number in bytes to a human-readable string. - ✔ Converts a number in bytes to a human-readable string. + √ prettyBytes is a Function + √ Converts a number in bytes to a human-readable string. + √ Converts a number in bytes to a human-readable string. + √ Converts a number in bytes to a human-readable string. Testing primes - ✔ primes is a Function - ✔ Generates primes up to a given number, using the Sieve of Eratosthenes. + √ primes is a Function + √ Generates primes up to a given number, using the Sieve of Eratosthenes. Testing promisify - ✔ promisify is a Function - ✔ Returns a promise + √ promisify is a Function + √ Returns a promise Testing pull - ✔ pull is a Function - ✔ Pulls the specified values + √ pull is a Function + √ Pulls the specified values Testing pullAtIndex - ✔ pullAtIndex is a Function - ✔ Pulls the given values - ✔ Pulls the given values + √ pullAtIndex is a Function + √ Pulls the given values + √ Pulls the given values Testing pullAtValue - ✔ pullAtValue is a Function - ✔ Pulls the specified values - ✔ Pulls the specified values + √ pullAtValue is a Function + √ Pulls the specified values + √ Pulls the specified values Testing pullBy - ✔ pullBy is a Function - ✔ Pulls the specified values + √ pullBy is a Function + √ Pulls the specified values Testing quickSort - ✔ quickSort is a Function - ✔ quickSort([5, 6, 4, 3, 1, 2]) returns [1, 2, 3, 4, 5, 6] - ✔ quickSort([-1, 0, -2]) returns [-2, -1, 0] - ✔ quickSort() throws an error - ✔ quickSort(123) throws an error - ✔ quickSort({ 234: string}) throws an error - ✔ quickSort(null) throws an error - ✔ quickSort(undefined) throws an error - ✔ quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run + √ quickSort is a Function + √ quickSort([5, 6, 4, 3, 1, 2]) returns [1, 2, 3, 4, 5, 6] + √ quickSort([-1, 0, -2]) returns [-2, -1, 0] + √ quickSort() throws an error + √ quickSort(123) throws an error + √ quickSort({ 234: string}) throws an error + √ quickSort(null) throws an error + √ quickSort(undefined) throws an error + √ quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run Testing randomHexColorCode - ✔ randomHexColorCode is a Function - ✔ should be equal + √ randomHexColorCode is a Function + √ should be equal Testing randomIntArrayInRange - ✔ randomIntArrayInRange is a Function - ✔ The returned array contains only integers - ✔ The returned array has the proper length - ✔ The returned array's values lie between provided lowerLimit and upperLimit (both inclusive). + √ randomIntArrayInRange is a Function + √ The returned array contains only integers + √ The returned array has the proper length + √ The returned array's values lie between provided lowerLimit and upperLimit (both inclusive). Testing randomIntegerInRange - ✔ randomIntegerInRange is a Function - ✔ The returned value is an integer - ✔ The returned value lies between provided lowerLimit and upperLimit (both inclusive). + √ randomIntegerInRange is a Function + √ The returned value is an integer + √ The returned value lies between provided lowerLimit and upperLimit (both inclusive). Testing randomNumberInRange - ✔ randomNumberInRange is a Function - ✔ The returned value is a number - ✔ The returned value lies between provided lowerLimit and upperLimit (both inclusive). + √ randomNumberInRange is a Function + √ The returned value is a number + √ The returned value lies between provided lowerLimit and upperLimit (both inclusive). Testing readFileLines - ✔ readFileLines is a Function - ✔ Tested on 09/02/2018 by @chalarangelo + √ readFileLines is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing rearg - ✔ rearg is a Function - ✔ Reorders arguments in invoked function + √ rearg is a Function + √ Reorders arguments in invoked function Testing redirect - ✔ redirect is a Function - ✔ Tested on 09/02/2018 by @chalarangelo - - Testing reduceSuccessive - - ✔ reduceSuccessive is a Function - ✔ Returns the array of successively reduced values - - Testing reduceWhich - - ✔ reduceWhich is a Function - ✔ Returns the minimum of an array - ✔ Returns the maximum of an array - ✔ Returns the object with the minimum specified value in an array + √ redirect is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing reducedFilter - ✔ reducedFilter is a Function - ✔ Filter an array of objects based on a condition while also filtering out unspecified keys. + √ reducedFilter is a Function + √ Filter an array of objects based on a condition while also filtering out unspecified keys. + + Testing reduceSuccessive + + √ reduceSuccessive is a Function + √ Returns the array of successively reduced values + + Testing reduceWhich + + √ reduceWhich is a Function + √ Returns the minimum of an array + √ Returns the maximum of an array + √ Returns the object with the minimum specified value in an array Testing remove - ✔ remove is a Function - ✔ Removes elements from an array for which the given function returns false + √ remove is a Function + √ Removes elements from an array for which the given function returns false Testing removeNonASCII - ✔ removeNonASCII is a Function - ✔ Removes non-ASCII characters + √ removeNonASCII is a Function + √ Removes non-ASCII characters Testing removeVowels - ✔ removeVowels is a Function + √ removeVowels is a Function Testing reverseString - ✔ reverseString is a Function - ✔ Reverses a string. + √ reverseString is a Function + √ Reverses a string. + + Testing RGBToHex + + √ RGBToHex is a Function + √ Converts the values of RGB components to a color code. Testing round - ✔ round is a Function - ✔ round(1.005, 2) returns 1.01 - ✔ round(123.3423345345345345344, 11) returns 123.34233453453 - ✔ round(3.342, 11) returns 3.342 - ✔ round(1.005) returns 1 - ✔ round([1.005, 2]) returns NaN - ✔ round(string) returns NaN - ✔ round() returns NaN - ✔ round(132, 413, 4134) returns NaN - ✔ round({a: 132}, 413) returns NaN - ✔ round(123.3423345345345345344, 11) takes less than 2s to run + √ round is a Function + √ round(1.005, 2) returns 1.01 + √ round(123.3423345345345345344, 11) returns 123.34233453453 + √ round(3.342, 11) returns 3.342 + √ round(1.005) returns 1 + √ round([1.005, 2]) returns NaN + √ round(string) returns NaN + √ round() returns NaN + √ round(132, 413, 4134) returns NaN + √ round({a: 132}, 413) returns NaN + √ round(123.3423345345345345344, 11) takes less than 2s to run Testing runAsync - ✔ runAsync is a Function - ✔ Tested on 09/02/2018 by @chalarangelo + √ runAsync is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing runPromisesInSeries - ✔ runPromisesInSeries is a Function + √ runPromisesInSeries is a Function Testing sample - ✔ sample is a Function - ✔ Returns a random element from the array - ✔ Works for single-element arrays - ✔ Returns undefined for empty array + √ sample is a Function + √ Returns a random element from the array + √ Works for single-element arrays + √ Returns undefined for empty array Testing sampleSize - ✔ sampleSize is a Function - ✔ Returns a single element without n specified - ✔ Returns a random sample of specified size from an array - ✔ Returns all elements in an array if n >= length - ✔ Returns an empty array if original array is empty - ✔ Returns an empty array if n = 0 + √ sampleSize is a Function + √ Returns a single element without n specified + √ Returns a random sample of specified size from an array + √ Returns all elements in an array if n >= length + √ Returns an empty array if original array is empty + √ Returns an empty array if n = 0 Testing scrollToTop - ✔ scrollToTop is a Function - ✔ Tested on 09/02/2018 by @chalarangelo + √ scrollToTop is a Function + √ Tested on 09/02/2018 by @chalarangelo Testing sdbm - ✔ sdbm is a Function - ✔ Hashes the input string into a whole number. + √ sdbm is a Function + √ Hashes the input string into a whole number. Testing serializeCookie - ✔ serializeCookie is a Function - ✔ Serializes the cookie + √ serializeCookie is a Function + √ Serializes the cookie Testing setStyle - ✔ setStyle is a Function + √ setStyle is a Function Testing shallowClone - ✔ shallowClone is a Function - ✔ Shallow cloning works - ✔ Does not clone deeply + √ shallowClone is a Function + √ Shallow cloning works + √ Does not clone deeply Testing show - ✔ show is a Function + √ show is a Function Testing shuffle - ✔ shuffle is a Function - ✔ Shuffles the array - ✔ New array contains all original elements - ✔ Works for empty arrays - ✔ Works for single-element arrays + √ shuffle is a Function + √ Shuffles the array + √ New array contains all original elements + √ Works for empty arrays + √ Works for single-element arrays Testing similarity - ✔ similarity is a Function - ✔ Returns an array of elements that appear in both arrays. + √ similarity is a Function + √ Returns an array of elements that appear in both arrays. Testing size - ✔ size is a Function - ✔ Get size of arrays, objects or strings. - ✔ Get size of arrays, objects or strings. + √ size is a Function + √ Get size of arrays, objects or strings. + √ Get size of arrays, objects or strings. Testing sleep - ✔ sleep is a Function + √ sleep is a Function Testing solveRPN - ✔ solveRPN is a Function + √ solveRPN is a Function Testing sortCharactersInString - ✔ sortCharactersInString is a Function - ✔ Alphabetically sorts the characters in a string. + √ sortCharactersInString is a Function + √ Alphabetically sorts the characters in a string. Testing sortedIndex - ✔ sortedIndex is a Function - ✔ Returns the lowest index at which value should be inserted into array in order to maintain its sort order. - ✔ Returns the lowest index at which value should be inserted into array in order to maintain its sort order. + √ sortedIndex is a Function + √ Returns the lowest index at which value should be inserted into array in order to maintain its sort order. + √ Returns the lowest index at which value should be inserted into array in order to maintain its sort order. Testing sortedIndexBy - ✔ sortedIndexBy is a Function - ✔ Returns the lowest index to insert the element without messing up the list order + √ sortedIndexBy is a Function + √ Returns the lowest index to insert the element without messing up the list order Testing sortedLastIndex - ✔ sortedLastIndex is a Function - ✔ Returns the highest index to insert the element without messing up the list order + √ sortedLastIndex is a Function + √ Returns the highest index to insert the element without messing up the list order Testing sortedLastIndexBy - ✔ sortedLastIndexBy is a Function - ✔ Returns the highest index to insert the element without messing up the list order + √ sortedLastIndexBy is a Function + √ Returns the highest index to insert the element without messing up the list order Testing speechSynthesis - ✔ speechSynthesis is a Function + √ speechSynthesis is a Function Testing splitLines - ✔ splitLines is a Function - ✔ Splits a multiline string into an array of lines. + √ splitLines is a Function + √ Splits a multiline string into an array of lines. Testing spreadOver - ✔ spreadOver is a Function - ✔ Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function. + √ spreadOver is a Function + √ Takes a variadic function and returns a closure that accepts an array of arguments to map to the inputs of the function. Testing standardDeviation - ✔ standardDeviation is a Function - ✔ Returns the standard deviation of an array of numbers - ✔ Returns the standard deviation of an array of numbers + √ standardDeviation is a Function + √ Returns the standard deviation of an array of numbers + √ Returns the standard deviation of an array of numbers Testing stripHTMLTags - ✔ stripHTMLTags is a Function - ✔ Removes HTML tags + √ stripHTMLTags is a Function + √ Removes HTML tags Testing sum - ✔ sum is a Function - ✔ Returns the sum of two or more numbers/arrays. + √ sum is a Function + √ Returns the sum of two or more numbers/arrays. Testing sumBy - ✔ sumBy is a Function + √ sumBy is a Function Testing sumPower - ✔ sumPower is a Function - ✔ Returns the sum of the powers of all the numbers from start to end - ✔ Returns the sum of the powers of all the numbers from start to end - ✔ Returns the sum of the powers of all the numbers from start to end + √ sumPower is a Function + √ Returns the sum of the powers of all the numbers from start to end + √ Returns the sum of the powers of all the numbers from start to end + √ Returns the sum of the powers of all the numbers from start to end Testing symmetricDifference - ✔ symmetricDifference is a Function - ✔ Returns the symmetric difference between two arrays. + √ symmetricDifference is a Function + √ Returns the symmetric difference between two arrays. Testing symmetricDifferenceBy - ✔ symmetricDifferenceBy is a Function - ✔ Returns the symmetric difference between two arrays, after applying the provided function to each array element of both + √ symmetricDifferenceBy is a Function + √ Returns the symmetric difference between two arrays, after applying the provided function to each array element of both Testing symmetricDifferenceWith - ✔ symmetricDifferenceWith is a Function - ✔ Returns the symmetric difference between two arrays, using a provided function as a comparator + √ symmetricDifferenceWith is a Function + √ Returns the symmetric difference between two arrays, using a provided function as a comparator Testing tail - ✔ tail is a Function - ✔ Returns tail - ✔ Returns tail + √ tail is a Function + √ Returns tail + √ Returns tail Testing take - ✔ take is a Function - ✔ Returns an array with n elements removed from the beginning. - ✔ Returns an array with n elements removed from the beginning. + √ take is a Function + √ Returns an array with n elements removed from the beginning. + √ Returns an array with n elements removed from the beginning. Testing takeRight - ✔ takeRight is a Function - ✔ Returns an array with n elements removed from the end - ✔ Returns an array with n elements removed from the end + √ takeRight is a Function + √ Returns an array with n elements removed from the end + √ Returns an array with n elements removed from the end Testing takeRightWhile - ✔ takeRightWhile is a Function - ✔ Removes elements until the function returns true + √ takeRightWhile is a Function + √ Removes elements until the function returns true Testing takeWhile - ✔ takeWhile is a Function - ✔ Removes elements until the function returns true + √ takeWhile is a Function + √ Removes elements until the function returns true Testing throttle - ✔ throttle is a Function - - Testing timeTaken - - ✔ timeTaken is a Function + √ throttle is a Function Testing times - ✔ times is a Function - ✔ Runs a function the specified amount of times + √ times is a Function + √ Runs a function the specified amount of times + + Testing timeTaken + + √ timeTaken is a Function Testing toCamelCase - ✔ toCamelCase is a Function - ✔ toCamelCase('some_database_field_name') returns someDatabaseFieldName - ✔ toCamelCase('Some label that needs to be camelized') returns someLabelThatNeedsToBeCamelized - ✔ toCamelCase('some-javascript-property') return someJavascriptProperty - ✔ toCamelCase('some-mixed_string with spaces_underscores-and-hyphens') returns someMixedStringWithSpacesUnderscoresAndHyphens - ✔ toCamelCase() throws a error - ✔ toCamelCase([]) throws a error - ✔ toCamelCase({}) throws a error - ✔ toCamelCase(123) throws a error - ✔ toCamelCase(some-mixed_string with spaces_underscores-and-hyphens) takes less than 2s to run + √ toCamelCase is a Function + √ toCamelCase('some_database_field_name') returns someDatabaseFieldName + √ toCamelCase('Some label that needs to be camelized') returns someLabelThatNeedsToBeCamelized + √ toCamelCase('some-javascript-property') return someJavascriptProperty + √ toCamelCase('some-mixed_string with spaces_underscores-and-hyphens') returns someMixedStringWithSpacesUnderscoresAndHyphens + √ toCamelCase() throws a error + √ toCamelCase([]) throws a error + √ toCamelCase({}) throws a error + √ toCamelCase(123) throws a error + √ toCamelCase(some-mixed_string with spaces_underscores-and-hyphens) takes less than 2s to run Testing toCurrency - ✔ toCurrency is a Function - ✔ currency: Euro | currencyLangFormat: Local - ✔ currency: US Dollar | currencyLangFormat: English (United States) - ✔ currency: Japanese Yen | currencyLangFormat: Local + √ toCurrency is a Function + √ currency: Euro | currencyLangFormat: Local + √ currency: US Dollar | currencyLangFormat: English (United States) + √ currency: Japanese Yen | currencyLangFormat: Local Testing toDecimalMark - ✔ toDecimalMark is a Function - ✔ convert a float-point arithmetic to the Decimal mark form - - Testing toKebabCase - - ✔ toKebabCase is a Function - ✔ toKebabCase('camelCase') returns camel-case - ✔ toKebabCase('some text') returns some-text - ✔ toKebabCase('some-mixed-string With spaces-underscores-and-hyphens') returns some-mixed-string-with-spaces-underscores-and-hyphens - ✔ toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html - ✔ toKebabCase() return undefined - ✔ toKebabCase([]) throws an error - ✔ toKebabCase({}) throws an error - ✔ toKebabCase(123) throws an error - ✔ toKebabCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run - - Testing toOrdinalSuffix - - ✔ toOrdinalSuffix is a Function - ✔ Adds an ordinal suffix to a number - ✔ Adds an ordinal suffix to a number - ✔ Adds an ordinal suffix to a number - ✔ Adds an ordinal suffix to a number - - Testing toSafeInteger - - ✔ toSafeInteger is a Function - ✔ Number(toSafeInteger(3.2)) is a number - ✔ Converts a value to a safe integer - ✔ toSafeInteger('4.2') returns 4 - ✔ toSafeInteger(4.6) returns 5 - ✔ toSafeInteger([]) returns 0 - ✔ isNaN(toSafeInteger([1.5, 3124])) is true - ✔ isNaN(toSafeInteger('string')) is true - ✔ isNaN(toSafeInteger({})) is true - ✔ isNaN(toSafeInteger()) is true - ✔ toSafeInteger(Infinity) returns 9007199254740991 - ✔ toSafeInteger(3.2) takes less than 2s to run - - Testing toSnakeCase - - ✔ toSnakeCase is a Function - ✔ toSnakeCase('camelCase') returns camel_case - ✔ toSnakeCase('some text') returns some_text - ✔ toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens') returns some_mixed_string_with_spaces_underscores_and_hyphens - ✔ toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html - ✔ toSnakeCase() returns undefined - ✔ toSnakeCase([]) throws an error - ✔ toSnakeCase({}) throws an error - ✔ toSnakeCase(123) throws an error - ✔ toSnakeCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run + √ toDecimalMark is a Function + √ convert a float-point arithmetic to the Decimal mark form Testing toggleClass - ✔ toggleClass is a Function + √ toggleClass is a Function + + Testing toKebabCase + + √ toKebabCase is a Function + √ toKebabCase('camelCase') returns camel-case + √ toKebabCase('some text') returns some-text + √ toKebabCase('some-mixed-string With spaces-underscores-and-hyphens') returns some-mixed-string-with-spaces-underscores-and-hyphens + √ toKebabCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i-am-listening-to-fm-while-loading-different-url-on-my-browser-and-also-editing-some-xml-and-html + √ toKebabCase() return undefined + √ toKebabCase([]) throws an error + √ toKebabCase({}) throws an error + √ toKebabCase(123) throws an error + √ toKebabCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run Testing tomorrow - ✔ tomorrow is a Function - ✔ Returns the correct year - ✔ Returns the correct month - ✔ Returns the correct date + √ tomorrow is a Function + √ Returns the correct year + √ Returns the correct month + √ Returns the correct date + + Testing toOrdinalSuffix + + √ toOrdinalSuffix is a Function + √ Adds an ordinal suffix to a number + √ Adds an ordinal suffix to a number + √ Adds an ordinal suffix to a number + √ Adds an ordinal suffix to a number + + Testing toSafeInteger + + √ toSafeInteger is a Function + √ Number(toSafeInteger(3.2)) is a number + √ Converts a value to a safe integer + √ toSafeInteger('4.2') returns 4 + √ toSafeInteger(4.6) returns 5 + √ toSafeInteger([]) returns 0 + √ isNaN(toSafeInteger([1.5, 3124])) is true + √ isNaN(toSafeInteger('string')) is true + √ isNaN(toSafeInteger({})) is true + √ isNaN(toSafeInteger()) is true + √ toSafeInteger(Infinity) returns 9007199254740991 + √ toSafeInteger(3.2) takes less than 2s to run + + Testing toSnakeCase + + √ toSnakeCase is a Function + √ toSnakeCase('camelCase') returns camel_case + √ toSnakeCase('some text') returns some_text + √ toSnakeCase('some-mixed_string With spaces_underscores-and-hyphens') returns some_mixed_string_with_spaces_underscores_and_hyphens + √ toSnakeCase('IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML') returns i_am_listening_to_fm_while_loading_different_url_on_my_browser_and_also_editing_some_xml_and_html + √ toSnakeCase() returns undefined + √ toSnakeCase([]) throws an error + √ toSnakeCase({}) throws an error + √ toSnakeCase(123) throws an error + √ toSnakeCase(IAmListeningToFMWhileLoadingDifferentURLOnMyBrowserAndAlsoEditingSomeXMLAndHTML) takes less than 2s to run Testing transform - ✔ transform is a Function - ✔ Transforms an object + √ transform is a Function + √ Transforms an object Testing truncateString - ✔ truncateString is a Function - ✔ Truncates a "boomerang" up to a specified length. + √ truncateString is a Function + √ Truncates a "boomerang" up to a specified length. Testing truthCheckCollection - ✔ truthCheckCollection is a Function - ✔ second argument is truthy on all elements of a collection + √ truthCheckCollection is a Function + √ second argument is truthy on all elements of a collection Testing unary - ✔ unary is a Function - ✔ Discards arguments after the first one + √ unary is a Function + √ Discards arguments after the first one + + Testing uncurry + + √ uncurry is a Function + √ Works without a provided value for n + √ Works without n = 2 + √ Works withoutn = 3 Testing unescapeHTML - ✔ unescapeHTML is a Function - ✔ Unescapes escaped HTML characters. + √ unescapeHTML is a Function + √ Unescapes escaped HTML characters. Testing unflattenObject - ✔ unflattenObject is a Function - ✔ Unflattens an object with the paths for keys + √ unflattenObject is a Function + √ Unflattens an object with the paths for keys Testing unfold - ✔ unfold is a Function - ✔ Works with a given function, producing an array + √ unfold is a Function + √ Works with a given function, producing an array Testing union - ✔ union is a Function - ✔ union([1, 2, 3], [4, 3, 2]) returns [1, 2, 3, 4] - ✔ union('str', 'asd') returns [ 's', 't', 'r', 'a', 'd' ] - ✔ union([[], {}], [1, 2, 3]) returns [[], {}, 1, 2, 3] - ✔ union([], []) returns [] - ✔ union() throws an error - ✔ union(true, str) throws an error - ✔ union(false, true) throws an error - ✔ union(123, {}) throws an error - ✔ union([], {}) throws an error - ✔ union(undefined, null) throws an error - ✔ union([1, 2, 3], [4, 3, 2]) takes less than 2s to run + √ union is a Function + √ union([1, 2, 3], [4, 3, 2]) returns [1, 2, 3, 4] + √ union('str', 'asd') returns [ 's', 't', 'r', 'a', 'd' ] + √ union([[], {}], [1, 2, 3]) returns [[], {}, 1, 2, 3] + √ union([], []) returns [] + √ union() throws an error + √ union(true, str) throws an error + √ union(false, true) throws an error + √ union(123, {}) throws an error + √ union([], {}) throws an error + √ union(undefined, null) throws an error + √ union([1, 2, 3], [4, 3, 2]) takes less than 2s to run Testing unionBy - ✔ unionBy is a Function - ✔ Produces the appropriate results + √ unionBy is a Function + √ Produces the appropriate results Testing unionWith - ✔ unionWith is a Function - ✔ Produces the appropriate results + √ unionWith is a Function + √ Produces the appropriate results Testing uniqueElements - ✔ uniqueElements is a Function - ✔ uniqueElements([1, 2, 2, 3, 4, 4, 5]) returns [1,2,3,4,5] - ✔ uniqueElements([1, 23, 53]) returns [1, 23, 53] - ✔ uniqueElements([true, 0, 1, false, false, undefined, null, '']) returns [true, 0, 1, false, false, undefined, null, ''] - ✔ uniqueElements() returns [] - ✔ uniqueElements(null) returns [] - ✔ uniqueElements(undefined) returns [] - ✔ uniqueElements('strt') returns ['s', 't', 'r'] - ✔ uniqueElements(1, 1, 2543, 534, 5) throws an error - ✔ uniqueElements({}) throws an error - ✔ uniqueElements(true) throws an error - ✔ uniqueElements(false) throws an error - ✔ uniqueElements([true, 0, 1, false, false, undefined, null]) takes less than 2s to run + √ uniqueElements is a Function + √ uniqueElements([1, 2, 2, 3, 4, 4, 5]) returns [1,2,3,4,5] + √ uniqueElements([1, 23, 53]) returns [1, 23, 53] + √ uniqueElements([true, 0, 1, false, false, undefined, null, '']) returns [true, 0, 1, false, false, undefined, null, ''] + √ uniqueElements() returns [] + √ uniqueElements(null) returns [] + √ uniqueElements(undefined) returns [] + √ uniqueElements('strt') returns ['s', 't', 'r'] + √ uniqueElements(1, 1, 2543, 534, 5) throws an error + √ uniqueElements({}) throws an error + √ uniqueElements(true) throws an error + √ uniqueElements(false) throws an error + √ uniqueElements([true, 0, 1, false, false, undefined, null]) takes less than 2s to run Testing untildify - ✔ untildify is a Function - ✔ Contains no tildes - ✔ Does not alter the rest of the path - ✔ Does not alter paths without tildes + √ untildify is a Function + √ Contains no tildes + √ Does not alter the rest of the path + √ Does not alter paths without tildes Testing unzip - ✔ unzip is a Function - ✔ unzip([['a', 1, true], ['b', 2, false]]) equals [['a', 'b'], [1, 2], [true, false]] - ✔ unzip([['a', 1, true], ['b', 2]]) equals [['a', 'b'], [1, 2], [true]] + √ unzip is a Function + √ unzip([['a', 1, true], ['b', 2, false]]) equals [['a', 'b'], [1, 2], [true, false]] + √ unzip([['a', 1, true], ['b', 2]]) equals [['a', 'b'], [1, 2], [true]] Testing unzipWith - ✔ unzipWith is a Function - ✔ unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)) equals [3, 30, 300] + √ unzipWith is a Function + √ unzipWith([[1, 10, 100], [2, 20, 200]], (...args) => args.reduce((acc, v) => acc + v, 0)) equals [3, 30, 300] + + Testing URLJoin + + √ URLJoin is a Function + √ Returns proper URL + √ Returns proper URL + + Testing UUIDGeneratorBrowser + + √ UUIDGeneratorBrowser is a Function + √ Tested 09/02/2018 by @chalarangelo + + Testing UUIDGeneratorNode + + √ UUIDGeneratorNode is a Function + √ Contains dashes in the proper places + √ Only contains hexadecimal digits Testing validateNumber - ✔ validateNumber is a Function - ✔ validateNumber(9) returns true - ✔ validateNumber(234asd.slice(0, 2)) returns true - ✔ validateNumber(1232) returns true - ✔ validateNumber(1232 + 13423) returns true - ✔ validateNumber(1232 * 2342 * 123) returns true - ✔ validateNumber(1232.23423536) returns true - ✔ validateNumber(234asd) returns false - ✔ validateNumber(e234d) returns false - ✔ validateNumber(false) returns false - ✔ validateNumber(true) returns false - ✔ validateNumber(null) returns false - ✔ validateNumber(123 * asd) returns false + √ validateNumber is a Function + √ validateNumber(9) returns true + √ validateNumber(234asd.slice(0, 2)) returns true + √ validateNumber(1232) returns true + √ validateNumber(1232 + 13423) returns true + √ validateNumber(1232 * 2342 * 123) returns true + √ validateNumber(1232.23423536) returns true + √ validateNumber(234asd) returns false + √ validateNumber(e234d) returns false + √ validateNumber(false) returns false + √ validateNumber(true) returns false + √ validateNumber(null) returns false + √ validateNumber(123 * asd) returns false Testing without - ✔ without is a Function - ✔ without([2, 1, 2, 3], 1, 2) returns [3] - ✔ without([]) returns [] - ✔ without([3, 1, true, '3', true], '3', true) returns [3, 1] - ✔ without('string'.split(''), 's', 't', 'g') returns ['r', 'i', 'n'] - ✔ without() throws an error - ✔ without(null) throws an error - ✔ without(undefined) throws an error - ✔ without() throws an error - ✔ without({}) throws an error + √ without is a Function + √ without([2, 1, 2, 3], 1, 2) returns [3] + √ without([]) returns [] + √ without([3, 1, true, '3', true], '3', true) returns [3, 1] + √ without('string'.split(''), 's', 't', 'g') returns ['r', 'i', 'n'] + √ without() throws an error + √ without(null) throws an error + √ without(undefined) throws an error + √ without() throws an error + √ without({}) throws an error Testing words - ✔ words is a Function - ✔ words('I love javaScript!!') returns [I, love, javaScript] - ✔ words('python, javaScript & coffee') returns [python, javaScript, coffee] - ✔ words(I love javaScript!!) returns an array - ✔ words() throws a error - ✔ words(null) throws a error - ✔ words(undefined) throws a error - ✔ words({}) throws a error - ✔ words([]) throws a error - ✔ words(1234) throws a error + √ words is a Function + √ words('I love javaScript!!') returns [I, love, javaScript] + √ words('python, javaScript & coffee') returns [python, javaScript, coffee] + √ words(I love javaScript!!) returns an array + √ words() throws a error + √ words(null) throws a error + √ words(undefined) throws a error + √ words({}) throws a error + √ words([]) throws a error + √ words(1234) throws a error Testing xProd - ✔ xProd is a Function - ✔ xProd([1, 2], ['a', 'b']) returns [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] + √ xProd is a Function + √ xProd([1, 2], ['a', 'b']) returns [[1, 'a'], [1, 'b'], [2, 'a'], [2, 'b']] Testing yesNo - ✔ yesNo is a Function - ✔ yesNo(Y) returns true - ✔ yesNo(yes) returns true - ✔ yesNo(foo, true) returns true - ✔ yesNo(No) returns false - ✔ yesNo() returns false - ✔ yesNo(null) returns false - ✔ yesNo(undefined) returns false - ✔ yesNo([123, null]) returns false - ✔ yesNo([Yes, No]) returns false - ✔ yesNo({ 2: Yes }) returns false - ✔ yesNo([Yes, No], true) returns true - ✔ yesNo({ 2: Yes }, true) returns true + √ yesNo is a Function + √ yesNo(Y) returns true + √ yesNo(yes) returns true + √ yesNo(foo, true) returns true + √ yesNo(No) returns false + √ yesNo() returns false + √ yesNo(null) returns false + √ yesNo(undefined) returns false + √ yesNo([123, null]) returns false + √ yesNo([Yes, No]) returns false + √ yesNo({ 2: Yes }) returns false + √ yesNo([Yes, No], true) returns true + √ yesNo({ 2: Yes }, true) returns true Testing zip - ✔ zip is a Function - ✔ zip([a, b], [1, 2], [true, false]) returns [[a, 1, true], [b, 2, false]] - ✔ zip([a], [1, 2], [true, false]) returns [[a, 1, true], [undefined, 2, false]] - ✔ zip([]) returns [] - ✔ zip(123) returns [] - ✔ zip([a, b], [1, 2], [true, false]) returns an Array - ✔ zip([a], [1, 2], [true, false]) returns an Array - ✔ zip(null) throws an error - ✔ zip(undefined) throws an error + √ zip is a Function + √ zip([a, b], [1, 2], [true, false]) returns [[a, 1, true], [b, 2, false]] + √ zip([a], [1, 2], [true, false]) returns [[a, 1, true], [undefined, 2, false]] + √ zip([]) returns [] + √ zip(123) returns [] + √ zip([a, b], [1, 2], [true, false]) returns an Array + √ zip([a], [1, 2], [true, false]) returns an Array + √ zip(null) throws an error + √ zip(undefined) throws an error Testing zipObject - ✔ zipObject is a Function - ✔ zipObject([a, b, c], [1, 2]) returns {a: 1, b: 2, c: undefined} - ✔ zipObject([a, b], [1, 2, 3]) returns {a: 1, b: 2} - ✔ zipObject([a, b, c], string) returns { a: s, b: t, c: r } - ✔ zipObject([a], string) returns { a: s } - ✔ zipObject() throws an error - ✔ zipObject([string], null) throws an error - ✔ zipObject(null, [1]) throws an error - ✔ zipObject(string) throws an error - ✔ zipObject(test, string) throws an error + √ zipObject is a Function + √ zipObject([a, b, c], [1, 2]) returns {a: 1, b: 2, c: undefined} + √ zipObject([a, b], [1, 2, 3]) returns {a: 1, b: 2} + √ zipObject([a, b, c], string) returns { a: s, b: t, c: r } + √ zipObject([a], string) returns { a: s } + √ zipObject() throws an error + √ zipObject([string], null) throws an error + √ zipObject(null, [1]) throws an error + √ zipObject(string) throws an error + √ zipObject(test, string) throws an error Testing zipWith - ✔ zipWith is a Function - ✔ Runs the function provided - ✔ Sends a POST request - ✔ Runs promises in series - ✔ Sends a GET request - ✔ Works with multiple promises + √ zipWith is a Function + √ Runs the function provided + √ Sends a GET request + √ Runs promises in series + √ Sends a POST request + √ Works with multiple promises - total: 901 - passing: 901 - duration: 2.7s + total: 905 + passing: 905 + duration: 2.4s diff --git a/test/uncurry/uncurry.js b/test/uncurry/uncurry.js new file mode 100644 index 000000000..a926982d5 --- /dev/null +++ b/test/uncurry/uncurry.js @@ -0,0 +1,6 @@ +const uncurry = (fn, n = 1) => (...args) => { +const next = acc => args => args.reduce((x, y) => x(y), acc); +if (n > args.length) throw new RangeError('Arguments too few!'); +return next(fn)(args.slice(0, n)); +}; +module.exports = uncurry; \ No newline at end of file diff --git a/test/uncurry/uncurry.test.js b/test/uncurry/uncurry.test.js new file mode 100644 index 000000000..76ef507fa --- /dev/null +++ b/test/uncurry/uncurry.test.js @@ -0,0 +1,20 @@ +const test = require('tape'); +const uncurry = require('./uncurry.js'); + +test('Testing uncurry', (t) => { + //For more information on all the methods supported by tape + //Please go to https://github.com/substack/tape + t.true(typeof uncurry === 'function', 'uncurry is a Function'); + const add = x => y => z => x + y + z; + const add1 = uncurry(add); + const add2 = uncurry(add, 2); + const add3 = uncurry(add, 3); + t.equal(add1(1)(2)(3), 6, 'Works without a provided value for n'); + t.equal(add2(1,2)(3), 6, 'Works without n = 2'); + t.equal(add3(1,2,3), 6, 'Works withoutn = 3'); + //t.deepEqual(uncurry(args..), 'Expected'); + //t.equal(uncurry(args..), 'Expected'); + //t.false(uncurry(args..), 'Expected'); + //t.throws(uncurry(args..), 'Expected'); + t.end(); +}); From 4b9d00fe112a8f3c20fe0b28235e223c24c30659 Mon Sep 17 00:00:00 2001 From: 30secondsofcode <30secondsofcode@gmail.com> Date: Wed, 14 Feb 2018 09:58:38 +0000 Subject: [PATCH 02/10] Travis build: 1662 --- README.md | 33 +++++++++++++++++++++++++++++++++ docs/index.html | 10 +++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7083b13b8..94145e6ee 100644 --- a/README.md +++ b/README.md @@ -246,6 +246,7 @@ average(1, 2, 3); * [`sleep`](#sleep) * [`throttle`](#throttle) * [`times`](#times) +* [`uncurry`](#uncurry) * [`unfold`](#unfold) @@ -4199,6 +4200,38 @@ console.log(output); // 01234
[⬆ Back to top](#table-of-contents) +### uncurry + +Uncurries a function up to depth `n`. + +Return a variadic function. +Use `Array.reduce()` on the provided arguments to call each subsequent curry level of the function. +If the `length` of the provided arguments is less than `n` throw an error. +Otherwise, call `fn` with the proper amount of arguments, using `Array.slice(0, n)`. +Omit the second argument, `n`, to uncurry up to depth `1`. + +```js +const uncurry = (fn, n = 1) => (...args) => { + const next = acc => args => args.reduce((x, y) => x(y), acc); + if (n > args.length) throw new RangeError('Arguments too few!'); + return next(fn)(args.slice(0, n)); +}; +``` + +
+Examples + +```js +const add = x => y => z => x + y + z; +const uncurriedAdd = uncurry(add, 3); +uncurriedAdd(1, 2, 3); // 6 +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### unfold Builds an array, using an iterator function and an initial seed value. diff --git a/docs/index.html b/docs/index.html index 385f479a6..6404e8899 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,7 @@ scrollToTop(); } }, false); - }

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

 

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));
+      }

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

 

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));
 
const firstTwoMax = ary(Math.max, 2);
 [[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10]
 

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);
@@ -967,6 +967,14 @@ document.bodyShow examples
var output = '';
 times(5, i => (output += i));
 console.log(output); // 01234
+

uncurry

Uncurries a function up to depth n.

Return a variadic function. Use Array.reduce() on the provided arguments to call each subsequent curry level of the function. If the length of the provided arguments is less than n throw an error. Otherwise, call fn with the proper amount of arguments, using Array.slice(0, n). Omit the second argument, n, to uncurry up to depth 1.

const uncurry = (fn, n = 1) => (...args) => {
+  const next = acc => args => args.reduce((x, y) => x(y), acc);
+  if (n > args.length) throw new RangeError('Arguments too few!');
+  return next(fn)(args.slice(0, n));
+};
+
const add = x => y => z => x + y + z;
+const uncurriedAdd = uncurry(add, 3);
+uncurriedAdd(1, 2, 3); // 6
 

unfold

Builds an array, using an iterator function and an initial seed value.

Use a while loop and Array.push() to call the function repeatedly until it returns false. The iterator function accepts one argument (seed) and must always return an array with two elements ([value, nextSeed]) or false to terminate.

const unfold = (fn, seed) => {
   let result = [],
     val = [null, seed];

From a1a99021d3b782ddc4ae32dd6bdfc7d2ca87b29f Mon Sep 17 00:00:00 2001
From: Angelos Chalaris 
Date: Wed, 14 Feb 2018 12:13:07 +0200
Subject: [PATCH 03/10] Add bifurcate, bifurcateBy

---
 snippets/bifurcate.md                | 17 +++++++++++++++++
 snippets/bifurcateBy.md              | 17 +++++++++++++++++
 tag_database                         |  2 ++
 test/bifurcate/bifurcate.js          |  6 ++++++
 test/bifurcate/bifurcate.test.js     | 14 ++++++++++++++
 test/bifurcateBy/bifurcateBy.js      |  6 ++++++
 test/bifurcateBy/bifurcateBy.test.js | 14 ++++++++++++++
 test/testlog                         | 18 ++++++++++++++----
 8 files changed, 90 insertions(+), 4 deletions(-)
 create mode 100644 snippets/bifurcate.md
 create mode 100644 snippets/bifurcateBy.md
 create mode 100644 test/bifurcate/bifurcate.js
 create mode 100644 test/bifurcate/bifurcate.test.js
 create mode 100644 test/bifurcateBy/bifurcateBy.js
 create mode 100644 test/bifurcateBy/bifurcateBy.test.js

diff --git a/snippets/bifurcate.md b/snippets/bifurcate.md
new file mode 100644
index 000000000..4177c9483
--- /dev/null
+++ b/snippets/bifurcate.md
@@ -0,0 +1,17 @@
+### bifurcate
+
+Splits values into two groups. If an element in `filter` is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.
+
+Use `Array.reduce()` and `Array.push()` to add elements to groups, based on `filter`.
+
+```js
+const bifurcate = (arr, filter) =>
+  arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [
+    [],
+    [],
+  ]);
+```
+
+```js
+bifurcate([ 'beep', 'boop', 'foo', 'bar' ], [ true, true, false, true ]); // [ ['beep', 'boop', 'bar'], ['foo'] ]
+```
diff --git a/snippets/bifurcateBy.md b/snippets/bifurcateBy.md
new file mode 100644
index 000000000..23f81b06f
--- /dev/null
+++ b/snippets/bifurcateBy.md
@@ -0,0 +1,17 @@
+### bifurcateBy
+
+Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group.
+
+Use `Array.reduce()` and `Array.push()` to add elements to groups, based on the value returned by `fn` for each element.
+
+```js
+const bifurcateBy = (arr, fn) =>
+  arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [
+    [],
+    [],
+  ]);
+```
+
+```js
+bifurcateBy([ 'beep', 'boop', 'foo', 'bar' ], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ]
+```
diff --git a/tag_database b/tag_database
index 6459c8aae..c69f793c6 100644
--- a/tag_database
+++ b/tag_database
@@ -5,6 +5,8 @@ atob:node,string,utility
 attempt:function
 average:math,array
 averageBy:math,array,function
+bifurcate:array
+bifurcateBy:array,function
 bind:function,object
 bindAll:object,function
 bindKey:function,object
diff --git a/test/bifurcate/bifurcate.js b/test/bifurcate/bifurcate.js
new file mode 100644
index 000000000..86fc9f7c1
--- /dev/null
+++ b/test/bifurcate/bifurcate.js
@@ -0,0 +1,6 @@
+const bifurcate = (arr, filter) =>
+arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [
+[],
+[],
+]);
+module.exports = bifurcate;
\ No newline at end of file
diff --git a/test/bifurcate/bifurcate.test.js b/test/bifurcate/bifurcate.test.js
new file mode 100644
index 000000000..c65333ee0
--- /dev/null
+++ b/test/bifurcate/bifurcate.test.js
@@ -0,0 +1,14 @@
+const test = require('tape');
+const bifurcate = require('./bifurcate.js');
+
+test('Testing bifurcate', (t) => {
+  //For more information on all the methods supported by tape
+  //Please go to https://github.com/substack/tape
+  t.true(typeof bifurcate === 'function', 'bifurcate is a Function');
+  t.deepEqual(bifurcate([ 'beep', 'boop', 'foo', 'bar' ], [ true, true, false, true ]), [ ['beep', 'boop', 'bar'], ['foo'] ], 'Splits the collection into two groups');
+  //t.deepEqual(bifurcate(args..), 'Expected');
+  //t.equal(bifurcate(args..), 'Expected');
+  //t.false(bifurcate(args..), 'Expected');
+  //t.throws(bifurcate(args..), 'Expected');
+  t.end();
+});
diff --git a/test/bifurcateBy/bifurcateBy.js b/test/bifurcateBy/bifurcateBy.js
new file mode 100644
index 000000000..fb153edd7
--- /dev/null
+++ b/test/bifurcateBy/bifurcateBy.js
@@ -0,0 +1,6 @@
+const bifurcateBy = (arr, fn) =>
+arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [
+[],
+[],
+]);
+module.exports = bifurcateBy;
\ No newline at end of file
diff --git a/test/bifurcateBy/bifurcateBy.test.js b/test/bifurcateBy/bifurcateBy.test.js
new file mode 100644
index 000000000..a6c293638
--- /dev/null
+++ b/test/bifurcateBy/bifurcateBy.test.js
@@ -0,0 +1,14 @@
+const test = require('tape');
+const bifurcateBy = require('./bifurcateBy.js');
+
+test('Testing bifurcateBy', (t) => {
+  //For more information on all the methods supported by tape
+  //Please go to https://github.com/substack/tape
+  t.true(typeof bifurcateBy === 'function', 'bifurcateBy is a Function');
+  t.deepEqual(bifurcateBy([ 'beep', 'boop', 'foo', 'bar' ], x => x[0] === 'b'), [ ['beep', 'boop', 'bar'], ['foo'] ], 'Splits the collection into two groups');
+  //t.deepEqual(bifurcateBy(args..), 'Expected');
+  //t.equal(bifurcateBy(args..), 'Expected');
+  //t.false(bifurcateBy(args..), 'Expected');
+  //t.throws(bifurcateBy(args..), 'Expected');
+  t.end();
+});
diff --git a/test/testlog b/test/testlog
index 9ffd675a9..f7972c818 100644
--- a/test/testlog
+++ b/test/testlog
@@ -1,4 +1,4 @@
-Test log for: Wed Feb 14 2018 11:56:24 GMT+0200 (GTB Standard Time)
+Test log for: Wed Feb 14 2018 12:12:48 GMT+0200 (GTB Standard Time)
 
 > 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code
 > tape test/**/*.test.js | tap-spec
@@ -53,6 +53,16 @@ Test log for: Wed Feb 14 2018 11:56:24 GMT+0200 (GTB Standard Time)
     √ Produces the right result with a function
     √ Produces the right result with a property name
 
+  Testing bifurcate
+
+    √ bifurcate is a Function
+    √ Splits the collection into two groups
+
+  Testing bifurcateBy
+
+    √ bifurcateBy is a Function
+    √ Splits the collection into two groups
+
   Testing binarySearch
 
     √ binarySearch is a Function
@@ -1803,15 +1813,15 @@ Test log for: Wed Feb 14 2018 11:56:24 GMT+0200 (GTB Standard Time)
   Testing zipWith
 
     √ zipWith is a Function
-    √ Runs the function provided
     √ Sends a GET request
+    √ Runs the function provided
     √ Runs promises in series
     √ Sends a POST request
     √ Works with multiple promises
 
 
-  total:     905
-  passing:   905
+  total:     909
+  passing:   909
   duration:  2.4s
 
 

From 566653206bc18c62684759e170313254fbc90894 Mon Sep 17 00:00:00 2001
From: 30secondsofcode <30secondsofcode@gmail.com>
Date: Wed, 14 Feb 2018 10:14:34 +0000
Subject: [PATCH 04/10] Travis build: 1665

---
 README.md               | 48 +++++++++++++++++++++++++++++++++++++++++
 docs/index.html         | 10 +++++++--
 snippets/bifurcate.md   |  7 ++----
 snippets/bifurcateBy.md |  7 ++----
 4 files changed, 60 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md
index 94145e6ee..3189f39ca 100644
--- a/README.md
+++ b/README.md
@@ -98,6 +98,8 @@ average(1, 2, 3);
 
View contents +* [`bifurcate`](#bifurcate) +* [`bifurcateBy`](#bifurcateby) * [`chunk`](#chunk) * [`compact`](#compact) * [`countBy`](#countby) @@ -761,6 +763,52 @@ const unary = fn => val => fn(val); --- ## 📚 Array +### bifurcate + +Splits values into two groups. If an element in `filter` is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group. + +Use `Array.reduce()` and `Array.push()` to add elements to groups, based on `filter`. + +```js +const bifurcate = (arr, filter) => + arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]); +``` + +
+Examples + +```js +bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ] +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + +### bifurcateBy + +Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group. + +Use `Array.reduce()` and `Array.push()` to add elements to groups, based on the value returned by `fn` for each element. + +```js +const bifurcateBy = (arr, fn) => + arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]); +``` + +
+Examples + +```js +bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ] +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### chunk Chunks an array into smaller arrays of a specified size. diff --git a/docs/index.html b/docs/index.html index 6404e8899..1da3415cf 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,7 @@ scrollToTop(); } }, false); - }

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

 

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));
+      }

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

 

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));
 
const firstTwoMax = ary(Math.max, 2);
 [[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10]
 

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);
@@ -123,7 +123,13 @@ Object.assig
 arrayMax([1, 2, 3]); // 3
 

unary

Creates a function that accepts up to one argument, ignoring any additional arguments.

Call the provided function, fn, with just the first argument given.

const unary = fn => val => fn(val);
 
['6', '8', '10'].map(unary(parseInt)); // [6, 8, 10]
-

Array

chunk

Chunks an array into smaller arrays of a specified size.

Use Array.from() to create a new array, that fits the number of chunks that will be produced. Use Array.slice() to map each element of the new array to a chunk the length of size. If the original array can't be split evenly, the final chunk will contain the remaining elements.

const chunk = (arr, size) =>
+

Array

bifurcate

Splits values into two groups. If an element in filter is truthy, the corresponding element in the collection belongs to the first group; otherwise, it belongs to the second group.

Use Array.reduce() and Array.push() to add elements to groups, based on filter.

const bifurcate = (arr, filter) =>
+  arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
+
bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ]
+

bifurcateBy

Splits values into two groups according to a predicate function, which specifies which group an element in the input collection belongs to. If the predicate function returns a truthy value, the collection element belongs to the first group; otherwise, it belongs to the second group.

Use Array.reduce() and Array.push() to add elements to groups, based on the value returned by fn for each element.

const bifurcateBy = (arr, fn) =>
+  arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
+
bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ]
+

chunk

Chunks an array into smaller arrays of a specified size.

Use Array.from() to create a new array, that fits the number of chunks that will be produced. Use Array.slice() to map each element of the new array to a chunk the length of size. If the original array can't be split evenly, the final chunk will contain the remaining elements.

const chunk = (arr, size) =>
   Array.from({ length: Math.ceil(arr.length / size) }, (v, i) =>
     arr.slice(i * size, i * size + size)
   );
diff --git a/snippets/bifurcate.md b/snippets/bifurcate.md
index 4177c9483..2e124711f 100644
--- a/snippets/bifurcate.md
+++ b/snippets/bifurcate.md
@@ -6,12 +6,9 @@ Use `Array.reduce()` and `Array.push()` to add elements to groups, based on `fil
 
 ```js
 const bifurcate = (arr, filter) =>
-  arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [
-    [],
-    [],
-  ]);
+  arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
 ```
 
 ```js
-bifurcate([ 'beep', 'boop', 'foo', 'bar' ], [ true, true, false, true ]); // [ ['beep', 'boop', 'bar'], ['foo'] ]
+bifurcate(['beep', 'boop', 'foo', 'bar'], [true, true, false, true]); // [ ['beep', 'boop', 'bar'], ['foo'] ]
 ```
diff --git a/snippets/bifurcateBy.md b/snippets/bifurcateBy.md
index 23f81b06f..46a00116f 100644
--- a/snippets/bifurcateBy.md
+++ b/snippets/bifurcateBy.md
@@ -6,12 +6,9 @@ Use `Array.reduce()` and `Array.push()` to add elements to groups, based on the
 
 ```js
 const bifurcateBy = (arr, fn) =>
-  arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [
-    [],
-    [],
-  ]);
+  arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
 ```
 
 ```js
-bifurcateBy([ 'beep', 'boop', 'foo', 'bar' ], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ]
+bifurcateBy(['beep', 'boop', 'foo', 'bar'], x => x[0] === 'b'); // [ ['beep', 'boop', 'bar'], ['foo'] ]
 ```

From 4590cf2b9572d6ec31032b1e3712d3949602f043 Mon Sep 17 00:00:00 2001
From: Angelos Chalaris 
Date: Wed, 14 Feb 2018 12:24:50 +0200
Subject: [PATCH 05/10] Add degreesToRads and radsToDegrees

---
 snippet-template.md                      |  2 +-
 snippets/degreesToRads.md                | 13 +++++++++++++
 snippets/radsToDegrees.md                | 13 +++++++++++++
 tag_database                             |  2 ++
 test/bifurcate/bifurcate.js              |  5 +----
 test/bifurcateBy/bifurcateBy.js          |  5 +----
 test/degreesToRads/degreesToRads.js      |  2 ++
 test/degreesToRads/degreesToRads.test.js | 15 +++++++++++++++
 test/radsToDegrees/radsToDegrees.js      |  2 ++
 test/radsToDegrees/radsToDegrees.test.js | 14 ++++++++++++++
 test/testlog                             | 16 +++++++++++++---
 11 files changed, 77 insertions(+), 12 deletions(-)
 create mode 100644 snippets/degreesToRads.md
 create mode 100644 snippets/radsToDegrees.md
 create mode 100644 test/degreesToRads/degreesToRads.js
 create mode 100644 test/degreesToRads/degreesToRads.test.js
 create mode 100644 test/radsToDegrees/radsToDegrees.js
 create mode 100644 test/radsToDegrees/radsToDegrees.test.js

diff --git a/snippet-template.md b/snippet-template.md
index 1ee62a2f0..31cc8b26d 100644
--- a/snippet-template.md
+++ b/snippet-template.md
@@ -10,5 +10,5 @@ const functionName = arguments =>
 ```
 
 ```js
-functionName('sampleInput') // 'sampleOutput'
+functionName('sampleInput'); // 'sampleOutput'
 ```
diff --git a/snippets/degreesToRads.md b/snippets/degreesToRads.md
new file mode 100644
index 000000000..ed3a2ee0e
--- /dev/null
+++ b/snippets/degreesToRads.md
@@ -0,0 +1,13 @@
+### degreesToRads
+
+Converts an angle from degrees to radians.
+
+Use `Math.PI` and the degree to radian formula to convert the angle from degrees to radians.
+
+```js
+const degreesToRads = deg => deg * Math.PI / 180.0;
+```
+
+```js
+degreesToRads(90.0); // ~1.5708
+```
diff --git a/snippets/radsToDegrees.md b/snippets/radsToDegrees.md
new file mode 100644
index 000000000..d8dd54958
--- /dev/null
+++ b/snippets/radsToDegrees.md
@@ -0,0 +1,13 @@
+### radsToDegrees
+
+Converts an angle from radians to degrees.
+
+Use `Math.PI` and the radian to degree formula to convert the angle from radians to degrees.
+
+```js
+const radsToDegrees = rad => rad * 180.0 / Math.PI;
+```
+
+```js
+radsToDegrees(Math.PI / 2); // 90
+```
diff --git a/tag_database b/tag_database
index c69f793c6..b608bd0c8 100644
--- a/tag_database
+++ b/tag_database
@@ -42,6 +42,7 @@ deepClone:object,recursion
 deepFlatten:array,recursion
 defaults:object
 defer:function
+degreesToRads:math
 delay:function
 detectDeviceType:browser
 difference:array,math
@@ -189,6 +190,7 @@ pull:array
 pullAtIndex:array
 pullAtValue:array
 pullBy:array,function,advanced
+radsToDegrees:math
 randomHexColorCode:utility,random
 randomIntArrayInRange:math,utility,random
 randomIntegerInRange:math,utility,random
diff --git a/test/bifurcate/bifurcate.js b/test/bifurcate/bifurcate.js
index 86fc9f7c1..95d7f8f50 100644
--- a/test/bifurcate/bifurcate.js
+++ b/test/bifurcate/bifurcate.js
@@ -1,6 +1,3 @@
 const bifurcate = (arr, filter) =>
-arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [
-[],
-[],
-]);
+arr.reduce((acc, val, i) => (acc[filter[i] ? 0 : 1].push(val), acc), [[], []]);
 module.exports = bifurcate;
\ No newline at end of file
diff --git a/test/bifurcateBy/bifurcateBy.js b/test/bifurcateBy/bifurcateBy.js
index fb153edd7..bdf04a7ce 100644
--- a/test/bifurcateBy/bifurcateBy.js
+++ b/test/bifurcateBy/bifurcateBy.js
@@ -1,6 +1,3 @@
 const bifurcateBy = (arr, fn) =>
-arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [
-[],
-[],
-]);
+arr.reduce((acc, val, i) => (acc[fn(val, i) ? 0 : 1].push(val), acc), [[], []]);
 module.exports = bifurcateBy;
\ No newline at end of file
diff --git a/test/degreesToRads/degreesToRads.js b/test/degreesToRads/degreesToRads.js
new file mode 100644
index 000000000..da6d51836
--- /dev/null
+++ b/test/degreesToRads/degreesToRads.js
@@ -0,0 +1,2 @@
+const degreesToRads = deg => deg * Math.PI / 180.0;
+module.exports = degreesToRads;
\ No newline at end of file
diff --git a/test/degreesToRads/degreesToRads.test.js b/test/degreesToRads/degreesToRads.test.js
new file mode 100644
index 000000000..8ec980a10
--- /dev/null
+++ b/test/degreesToRads/degreesToRads.test.js
@@ -0,0 +1,15 @@
+const test = require('tape');
+const degreesToRads = require('./degreesToRads.js');
+
+test('Testing degreesToRads', (t) => {
+  //For more information on all the methods supported by tape
+  //Please go to https://github.com/substack/tape
+  const approxeq = (v1,v2, diff = 0.001) => Math.abs(v1 - v2) < diff; // Use to account for rounding errors
+  t.true(typeof degreesToRads === 'function', 'degreesToRads is a Function');
+  t.true(approxeq(degreesToRads(90.0), Math.PI / 2), 'Returns the appropriate value');
+  //t.deepEqual(degreesToRads(args..), 'Expected');
+  //t.equal(degreesToRads(args..), 'Expected');
+  //t.false(degreesToRads(args..), 'Expected');
+  //t.throws(degreesToRads(args..), 'Expected');
+  t.end();
+});
diff --git a/test/radsToDegrees/radsToDegrees.js b/test/radsToDegrees/radsToDegrees.js
new file mode 100644
index 000000000..d9a370b78
--- /dev/null
+++ b/test/radsToDegrees/radsToDegrees.js
@@ -0,0 +1,2 @@
+const radsToDegrees = rad => rad * 180.0 / Math.PI;
+module.exports = radsToDegrees;
\ No newline at end of file
diff --git a/test/radsToDegrees/radsToDegrees.test.js b/test/radsToDegrees/radsToDegrees.test.js
new file mode 100644
index 000000000..446485d76
--- /dev/null
+++ b/test/radsToDegrees/radsToDegrees.test.js
@@ -0,0 +1,14 @@
+const test = require('tape');
+const radsToDegrees = require('./radsToDegrees.js');
+
+test('Testing radsToDegrees', (t) => {
+  //For more information on all the methods supported by tape
+  //Please go to https://github.com/substack/tape
+  t.true(typeof radsToDegrees === 'function', 'radsToDegrees is a Function');
+  t.equal(radsToDegrees(Math.PI / 2), 90, 'Returns the appropriate value');
+  //t.deepEqual(radsToDegrees(args..), 'Expected');
+  //t.equal(radsToDegrees(args..), 'Expected');
+  //t.false(radsToDegrees(args..), 'Expected');
+  //t.throws(radsToDegrees(args..), 'Expected');
+  t.end();
+});
diff --git a/test/testlog b/test/testlog
index f7972c818..f4af90680 100644
--- a/test/testlog
+++ b/test/testlog
@@ -1,4 +1,4 @@
-Test log for: Wed Feb 14 2018 12:12:48 GMT+0200 (GTB Standard Time)
+Test log for: Wed Feb 14 2018 12:24:07 GMT+0200 (GTB Standard Time)
 
 > 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code
 > tape test/**/*.test.js | tap-spec
@@ -278,6 +278,11 @@ Test log for: Wed Feb 14 2018 12:12:48 GMT+0200 (GTB Standard Time)
 
     √ defer is a Function
 
+  Testing degreesToRads
+
+    √ degreesToRads is a Function
+    √ Returns the appropriate value
+
   Testing delay
 
     √ delay is a Function
@@ -1221,6 +1226,11 @@ Test log for: Wed Feb 14 2018 12:12:48 GMT+0200 (GTB Standard Time)
     √ quickSort(undefined) throws an error
     √ quickSort([11, 1, 324, 23232, -1, 53, 2, 524, 32, 13, 156, 133, 62, 12, 4]) takes less than 2s to run
 
+  Testing radsToDegrees
+
+    √ radsToDegrees is a Function
+    √ Returns the appropriate value
+
   Testing randomHexColorCode
 
     √ randomHexColorCode is a Function
@@ -1820,8 +1830,8 @@ Test log for: Wed Feb 14 2018 12:12:48 GMT+0200 (GTB Standard Time)
     √ Works with multiple promises
 
 
-  total:     909
-  passing:   909
+  total:     913
+  passing:   913
   duration:  2.4s
 
 

From 4a7534f44cb08c0f1f70725be3409f88d22cec23 Mon Sep 17 00:00:00 2001
From: 30secondsofcode <30secondsofcode@gmail.com>
Date: Wed, 14 Feb 2018 10:26:47 +0000
Subject: [PATCH 06/10] Travis build: 1667

---
 README.md       | 46 ++++++++++++++++++++++++++++++++++++++++++++++
 docs/index.html |  6 +++++-
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 3189f39ca..0f083e4a2 100644
--- a/README.md
+++ b/README.md
@@ -261,6 +261,7 @@ average(1, 2, 3);
 * [`average`](#average)
 * [`averageBy`](#averageby)
 * [`clampNumber`](#clampnumber)
+* [`degreesToRads`](#degreestorads)
 * [`digitize`](#digitize)
 * [`distance`](#distance)
 * [`elo`](#elo-)
@@ -281,6 +282,7 @@ average(1, 2, 3);
 * [`percentile`](#percentile)
 * [`powerset`](#powerset)
 * [`primes`](#primes)
+* [`radsToDegrees`](#radstodegrees)
 * [`randomIntArrayInRange`](#randomintarrayinrange)
 * [`randomIntegerInRange`](#randomintegerinrange)
 * [`randomNumberInRange`](#randomnumberinrange)
@@ -4383,6 +4385,28 @@ clampNumber(1, -1, -5); // -1
 
[⬆ Back to top](#table-of-contents) +### degreesToRads + +Converts an angle from degrees to radians. + +Use `Math.PI` and the degree to radian formula to convert the angle from degrees to radians. + +```js +const degreesToRads = deg => deg * Math.PI / 180.0; +``` + +
+Examples + +```js +degreesToRads(90.0); // ~1.5708 +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### digitize Converts a number to an array of digits. @@ -4931,6 +4955,28 @@ primes(10); // [2,3,5,7]
[⬆ Back to top](#table-of-contents) +### radsToDegrees + +Converts an angle from radians to degrees. + +Use `Math.PI` and the radian to degree formula to convert the angle from radians to degrees. + +```js +const radsToDegrees = rad => rad * 180.0 / Math.PI; +``` + +
+Examples + +```js +radsToDegrees(Math.PI / 2); // 90 +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### randomIntArrayInRange Returns an array of n random integers in the specified range. diff --git a/docs/index.html b/docs/index.html index 1da3415cf..7aa7f51ad 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,7 @@ scrollToTop(); } }, false); - }

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

 

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));
+      }

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

 

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));
 
const firstTwoMax = ary(Math.max, 2);
 [[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10]
 

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);
@@ -1000,6 +1000,8 @@ console.log<
 

clampNumber

Clamps num within the inclusive range specified by the boundary values a and b.

If num falls within the range, return num. Otherwise, return the nearest number in the range.

const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
 
clampNumber(2, 3, 5); // 3
 clampNumber(1, -1, -5); // -1
+

degreesToRads

Converts an angle from degrees to radians.

Use Math.PI and the degree to radian formula to convert the angle from degrees to radians.

const degreesToRads = deg => deg * Math.PI / 180.0;
+
degreesToRads(90.0); // ~1.5708
 

digitize

Converts a number to an array of digits.

Convert the number to a string, using the spread operator (...) to build an array. Use Array.map() and parseInt() to transform each value to an integer.

const digitize = n => [...`${n}`].map(i => parseInt(i));
 
digitize(123); // [1, 2, 3]
 

distance

Returns the distance between two points.

Use Math.hypot() to calculate the Euclidean distance between two points.

const distance = (x0, y0, x1, y1) => Math.hypot(x1 - x0, y1 - y0);
@@ -1123,6 +1125,8 @@ own individual rating by supplying it as the third argument.
   return arr;
 };
 
primes(10); // [2,3,5,7]
+

radsToDegrees

Converts an angle from radians to degrees.

Use Math.PI and the radian to degree formula to convert the angle from radians to degrees.

const radsToDegrees = rad => rad * 180.0 / Math.PI;
+
radsToDegrees(Math.PI / 2); // 90
 

randomIntArrayInRange

Returns an array of n random integers in the specified range.

Use Array.from() to create an empty array of the specific length, Math.random() to generate a random number and map it to the desired range, using Math.floor() to make it an integer.

const randomIntArrayInRange = (min, max, n = 1) =>
   Array.from({ length: n }, () => Math.floor(Math.random() * (max - min + 1)) + min);
 
randomIntArrayInRange(12, 35, 10); // [ 34, 14, 27, 17, 30, 27, 20, 26, 21, 14 ]

From f1086e8a45cacdff2f97df8aa174250109f29936 Mon Sep 17 00:00:00 2001
From: Angelos Chalaris 
Date: Wed, 14 Feb 2018 12:34:02 +0200
Subject: [PATCH 07/10] Add binomialCoefficient

---
 snippets/binomialCoefficient.md               | 26 +++++++++++++++++++
 tag_database                                  |  1 +
 .../binomialCoefficient.js                    | 11 ++++++++
 .../binomialCoefficient.test.js               | 18 +++++++++++++
 test/testlog                                  | 15 ++++++++---
 5 files changed, 68 insertions(+), 3 deletions(-)
 create mode 100644 snippets/binomialCoefficient.md
 create mode 100644 test/binomialCoefficient/binomialCoefficient.js
 create mode 100644 test/binomialCoefficient/binomialCoefficient.test.js

diff --git a/snippets/binomialCoefficient.md b/snippets/binomialCoefficient.md
new file mode 100644
index 000000000..d5ff87d16
--- /dev/null
+++ b/snippets/binomialCoefficient.md
@@ -0,0 +1,26 @@
+### binomialCoefficient
+
+Evaluates the binomial coefficient of two integers `n` and `k`.
+
+Use `Number.isNaN()` to check if any of the two values is `NaN`.
+Check if `k` is less than `0`, greater than or equal to `n`, equal to `1` or `n - 1` and return the appropriate result.
+Check if `n - k` is less than `k` and switch their values accordingly.
+Loop from `2` through `k` and calculate the binomial coefficient.
+Use `Math.round()` to account for rounding errors in the calculation.
+
+```js
+const binomialCoefficient = (n, k) => {
+  if (Number.isNaN(n) || Number.isNaN(k)) return NaN;
+  if (k < 0 || k > n) return 0;
+  if (k === 0 || k === n) return 1;
+  if (k === 1 || k === n - 1) return n;
+  if (n - k < k) k = n - k;
+  let res = n;
+  for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;
+  return Math.round(res);
+};
+```
+
+```js
+binomialCoefficient(8, 2); // 28
+```
diff --git a/tag_database b/tag_database
index b608bd0c8..cad9870dc 100644
--- a/tag_database
+++ b/tag_database
@@ -10,6 +10,7 @@ bifurcateBy:array,function
 bind:function,object
 bindAll:object,function
 bindKey:function,object
+binomialCoefficient:math
 bottomVisible:browser
 btoa:node,string,utility
 byteSize:string
diff --git a/test/binomialCoefficient/binomialCoefficient.js b/test/binomialCoefficient/binomialCoefficient.js
new file mode 100644
index 000000000..a9808585d
--- /dev/null
+++ b/test/binomialCoefficient/binomialCoefficient.js
@@ -0,0 +1,11 @@
+const binomialCoefficient = (n, k) => {
+if (Number.isNaN(n) || Number.isNaN(k)) return NaN;
+if (k < 0 || k > n) return 0;
+if (k === 0 || k === n) return 1;
+if (k === 1 || k === n - 1) return n;
+if (n - k < k) k = n - k;
+let res = n;
+for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;
+return Math.round(res);
+};
+module.exports = binomialCoefficient;
\ No newline at end of file
diff --git a/test/binomialCoefficient/binomialCoefficient.test.js b/test/binomialCoefficient/binomialCoefficient.test.js
new file mode 100644
index 000000000..2f0e8ab20
--- /dev/null
+++ b/test/binomialCoefficient/binomialCoefficient.test.js
@@ -0,0 +1,18 @@
+const test = require('tape');
+const binomialCoefficient = require('./binomialCoefficient.js');
+
+test('Testing binomialCoefficient', (t) => {
+  //For more information on all the methods supported by tape
+  //Please go to https://github.com/substack/tape
+  t.true(typeof binomialCoefficient === 'function', 'binomialCoefficient is a Function');
+  t.equal(binomialCoefficient(8, 2), 28, 'Returns the appropriate value');
+  t.equal(binomialCoefficient(0, 0), 1, 'Returns the appropriate value');
+  t.equal(binomialCoefficient(5, 3), 10, 'Returns the appropriate value');
+  t.true(Number.isNaN(binomialCoefficient(NaN, 3)), 'Returns NaN');
+  t.true(Number.isNaN(binomialCoefficient(5, NaN)), 'Returns NaN');
+  //t.deepEqual(binomialCoefficient(args..), 'Expected');
+  //t.equal(binomialCoefficient(args..), 'Expected');
+  //t.false(binomialCoefficient(args..), 'Expected');
+  //t.throws(binomialCoefficient(args..), 'Expected');
+  t.end();
+});
diff --git a/test/testlog b/test/testlog
index f4af90680..ab29b55f5 100644
--- a/test/testlog
+++ b/test/testlog
@@ -1,4 +1,4 @@
-Test log for: Wed Feb 14 2018 12:24:07 GMT+0200 (GTB Standard Time)
+Test log for: Wed Feb 14 2018 12:33:42 GMT+0200 (GTB Standard Time)
 
 > 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code
 > tape test/**/*.test.js | tap-spec
@@ -86,6 +86,15 @@ Test log for: Wed Feb 14 2018 12:24:07 GMT+0200 (GTB Standard Time)
     √ bindKey is a Function
     √ Binds function to an object context
 
+  Testing binomialCoefficient
+
+    √ binomialCoefficient is a Function
+    √ Returns the appropriate value
+    √ Returns the appropriate value
+    √ Returns the appropriate value
+    √ Returns NaN
+    √ Returns NaN
+
   Testing bottomVisible
 
     √ bottomVisible is a Function
@@ -1830,8 +1839,8 @@ Test log for: Wed Feb 14 2018 12:24:07 GMT+0200 (GTB Standard Time)
     √ Works with multiple promises
 
 
-  total:     913
-  passing:   913
+  total:     919
+  passing:   919
   duration:  2.4s
 
 

From a8caa9c75dde9e7c58cff1bbc3e8c2a5ae7d42f9 Mon Sep 17 00:00:00 2001
From: 30secondsofcode <30secondsofcode@gmail.com>
Date: Wed, 14 Feb 2018 10:35:33 +0000
Subject: [PATCH 08/10] Travis build: 1669

---
 README.md       | 36 ++++++++++++++++++++++++++++++++++++
 docs/index.html | 13 ++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

diff --git a/README.md b/README.md
index 0f083e4a2..0b99c993a 100644
--- a/README.md
+++ b/README.md
@@ -260,6 +260,7 @@ average(1, 2, 3);
 
 * [`average`](#average)
 * [`averageBy`](#averageby)
+* [`binomialCoefficient`](#binomialcoefficient)
 * [`clampNumber`](#clampnumber)
 * [`degreesToRads`](#degreestorads)
 * [`digitize`](#digitize)
@@ -4361,6 +4362,41 @@ averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 5
 
[⬆ Back to top](#table-of-contents) +### binomialCoefficient + +Evaluates the binomial coefficient of two integers `n` and `k`. + +Use `Number.isNaN()` to check if any of the two values is `NaN`. +Check if `k` is less than `0`, greater than or equal to `n`, equal to `1` or `n - 1` and return the appropriate result. +Check if `n - k` is less than `k` and switch their values accordingly. +Loop from `2` through `k` and calculate the binomial coefficient. +Use `Math.round()` to account for rounding errors in the calculation. + +```js +const binomialCoefficient = (n, k) => { + if (Number.isNaN(n) || Number.isNaN(k)) return NaN; + if (k < 0 || k > n) return 0; + if (k === 0 || k === n) return 1; + if (k === 1 || k === n - 1) return n; + if (n - k < k) k = n - k; + let res = n; + for (let j = 2; j <= k; j++) res *= (n - j + 1) / j; + return Math.round(res); +}; +``` + +
+Examples + +```js +binomialCoefficient(8, 2); // 28 +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### clampNumber Clamps `num` within the inclusive range specified by the boundary values `a` and `b`. diff --git a/docs/index.html b/docs/index.html index 7aa7f51ad..45e2c52bc 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,7 @@ scrollToTop(); } }, false); - }

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

 

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));
+      }

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

 

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));
 
const firstTwoMax = ary(Math.max, 2);
 [[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10]
 

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);
@@ -997,6 +997,17 @@ console.log<
   arr.length;
 
averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], o => o.n); // 5
 averageBy([{ n: 4 }, { n: 2 }, { n: 8 }, { n: 6 }], 'n'); // 5
+

binomialCoefficient

Evaluates the binomial coefficient of two integers n and k.

Use Number.isNaN() to check if any of the two values is NaN. Check if k is less than 0, greater than or equal to n, equal to 1 or n - 1 and return the appropriate result. Check if n - k is less than k and switch their values accordingly. Loop from 2 through k and calculate the binomial coefficient. Use Math.round() to account for rounding errors in the calculation.

const binomialCoefficient = (n, k) => {
+  if (Number.isNaN(n) || Number.isNaN(k)) return NaN;
+  if (k < 0 || k > n) return 0;
+  if (k === 0 || k === n) return 1;
+  if (k === 1 || k === n - 1) return n;
+  if (n - k < k) k = n - k;
+  let res = n;
+  for (let j = 2; j <= k; j++) res *= (n - j + 1) / j;
+  return Math.round(res);
+};
+
binomialCoefficient(8, 2); // 28
 

clampNumber

Clamps num within the inclusive range specified by the boundary values a and b.

If num falls within the range, return num. Otherwise, return the nearest number in the range.

const clampNumber = (num, a, b) => Math.max(Math.min(num, Math.max(a, b)), Math.min(a, b));
 
clampNumber(2, 3, 5); // 3
 clampNumber(1, -1, -5); // -1

From ba59e8020accabab1e65770551d60fc85db7c96b Mon Sep 17 00:00:00 2001
From: Angelos Chalaris 
Date: Wed, 14 Feb 2018 12:47:13 +0200
Subject: [PATCH 09/10] Add approximatelyEqual

---
 snippets/approximatelyEqual.md                  | 14 ++++++++++++++
 tag_database                                    |  1 +
 test/approximatelyEqual/approximatelyEqual.js   |  2 ++
 .../approximatelyEqual.test.js                  | 17 +++++++++++++++++
 test/testlog                                    | 16 ++++++++++++----
 5 files changed, 46 insertions(+), 4 deletions(-)
 create mode 100644 snippets/approximatelyEqual.md
 create mode 100644 test/approximatelyEqual/approximatelyEqual.js
 create mode 100644 test/approximatelyEqual/approximatelyEqual.test.js

diff --git a/snippets/approximatelyEqual.md b/snippets/approximatelyEqual.md
new file mode 100644
index 000000000..e93864536
--- /dev/null
+++ b/snippets/approximatelyEqual.md
@@ -0,0 +1,14 @@
+### approximatelyEqual
+
+Checks if two numbers are approximately equal to each other.
+
+Use `Math.abs()` to compare the absolute difference of the two values to `epsilon`.
+Omit the third parameter, `epsilon`, to use a default value of `0.001`.
+
+```js
+const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
+```
+
+```js
+approximatelyEqual(Math.PI / 2.0 , 1.5708); // true
+```
diff --git a/tag_database b/tag_database
index cad9870dc..09ba68764 100644
--- a/tag_database
+++ b/tag_database
@@ -1,4 +1,5 @@
 anagrams:string,recursion
+approximatelyEqual:math
 arrayToHtmlList:browser,array
 ary:adapter,function
 atob:node,string,utility
diff --git a/test/approximatelyEqual/approximatelyEqual.js b/test/approximatelyEqual/approximatelyEqual.js
new file mode 100644
index 000000000..85fecb15b
--- /dev/null
+++ b/test/approximatelyEqual/approximatelyEqual.js
@@ -0,0 +1,2 @@
+const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
+module.exports = approximatelyEqual;
\ No newline at end of file
diff --git a/test/approximatelyEqual/approximatelyEqual.test.js b/test/approximatelyEqual/approximatelyEqual.test.js
new file mode 100644
index 000000000..44221aeb8
--- /dev/null
+++ b/test/approximatelyEqual/approximatelyEqual.test.js
@@ -0,0 +1,17 @@
+const test = require('tape');
+const approximatelyEqual = require('./approximatelyEqual.js');
+
+test('Testing approximatelyEqual', (t) => {
+  //For more information on all the methods supported by tape
+  //Please go to https://github.com/substack/tape
+  t.true(typeof approximatelyEqual === 'function', 'approximatelyEqual is a Function');
+  t.true(approximatelyEqual(Math.PI / 2.0 , 1.5708), 'Works for PI / 2');
+  t.true(approximatelyEqual(0.1 + 0.2, 0.3), 'Works for 0.1 + 0.2 === 0.3');
+  t.true(approximatelyEqual(0.5, 0.5), 'Works for exactly equal values');
+  t.true(approximatelyEqual(0.501, 0.5, 0.1), 'Works for a custom epsilon');
+  //t.deepEqual(approximatelyEqual(args..), 'Expected');
+  //t.equal(approximatelyEqual(args..), 'Expected');
+  //t.false(approximatelyEqual(args..), 'Expected');
+  //t.throws(approximatelyEqual(args..), 'Expected');
+  t.end();
+});
diff --git a/test/testlog b/test/testlog
index ab29b55f5..804151df6 100644
--- a/test/testlog
+++ b/test/testlog
@@ -1,4 +1,4 @@
-Test log for: Wed Feb 14 2018 12:33:42 GMT+0200 (GTB Standard Time)
+Test log for: Wed Feb 14 2018 12:46:59 GMT+0200 (GTB Standard Time)
 
 > 30-seconds-of-code@0.0.1 test G:\My Files\git Repositories\30-seconds-of-code
 > tape test/**/*.test.js | tap-spec
@@ -11,6 +11,14 @@ Test log for: Wed Feb 14 2018 12:33:42 GMT+0200 (GTB Standard Time)
     √ Works for single-letter strings
     √ Works for empty strings
 
+  Testing approximatelyEqual
+
+    √ approximatelyEqual is a Function
+    √ Works for PI / 2
+    √ Works for 0.1 + 0.2 === 0.3
+    √ Works for exactly equal values
+    √ Works for a custom epsilon
+
   Testing arrayToHtmlList
 
     √ arrayToHtmlList is a Function
@@ -1839,8 +1847,8 @@ Test log for: Wed Feb 14 2018 12:33:42 GMT+0200 (GTB Standard Time)
     √ Works with multiple promises
 
 
-  total:     919
-  passing:   919
-  duration:  2.4s
+  total:     924
+  passing:   924
+  duration:  2.5s
 
 

From 422e5be4868e82313b6fc7114575314be6f1be5b Mon Sep 17 00:00:00 2001
From: 30secondsofcode <30secondsofcode@gmail.com>
Date: Wed, 14 Feb 2018 10:48:38 +0000
Subject: [PATCH 10/10] Travis build: 1671

---
 README.md                      | 24 ++++++++++++++++++++++++
 docs/index.html                |  6 ++++--
 snippets/approximatelyEqual.md |  2 +-
 3 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/README.md b/README.md
index 0b99c993a..5194f20c3 100644
--- a/README.md
+++ b/README.md
@@ -258,6 +258,7 @@ average(1, 2, 3);
 
View contents +* [`approximatelyEqual`](#approximatelyequal) * [`average`](#average) * [`averageBy`](#averageby) * [`binomialCoefficient`](#binomialcoefficient) @@ -4314,6 +4315,29 @@ unfold(f, 10); // [-10, -20, -30, -40, -50] --- ## ➗ Math +### approximatelyEqual + +Checks if two numbers are approximately equal to each other. + +Use `Math.abs()` to compare the absolute difference of the two values to `epsilon`. +Omit the third parameter, `epsilon`, to use a default value of `0.001`. + +```js +const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon; +``` + +
+Examples + +```js +approximatelyEqual(Math.PI / 2.0, 1.5708); // true +``` + +
+ +
[⬆ Back to top](#table-of-contents) + + ### average Returns the average of two or more numbers. diff --git a/docs/index.html b/docs/index.html index 45e2c52bc..75890c2f5 100644 --- a/docs/index.html +++ b/docs/index.html @@ -50,7 +50,7 @@ scrollToTop(); } }, false); - }

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

 

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));
+      }

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

 

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));
 
const firstTwoMax = ary(Math.max, 2);
 [[2, 6, 'a'], [8, 4, 6], [10]].map(x => firstTwoMax(...x)); // [6, 8, 10]
 

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);
@@ -989,7 +989,9 @@ console.log<
 };
 
var f = n => (n > 50 ? false : [-n, n + 10]);
 unfold(f, 10); // [-10, -20, -30, -40, -50]
-

Math

average

Returns the average of two or more numbers.

Use Array.reduce() to add each value to an accumulator, initialized with a value of 0, divide by the length of the array.

const average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
+

Math

approximatelyEqual

Checks if two numbers are approximately equal to each other.

Use Math.abs() to compare the absolute difference of the two values to epsilon. Omit the third parameter, epsilon, to use a default value of 0.001.

const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsilon;
+
approximatelyEqual(Math.PI / 2.0, 1.5708); // true
+

average

Returns the average of two or more numbers.

Use Array.reduce() to add each value to an accumulator, initialized with a value of 0, divide by the length of the array.

const average = (...nums) => [...nums].reduce((acc, val) => acc + val, 0) / nums.length;
 
average(...[1, 2, 3]); // 2
 average(1, 2, 3); // 2
 

averageBy

Returns the average of an array, after mapping each element to a value using the provided function.

Use Array.map() to map each element to the value returned by fn, Array.reduce() to add each value to an accumulator, initialized with a value of 0, divide by the length of the array.

const averageBy = (arr, fn) =>
diff --git a/snippets/approximatelyEqual.md b/snippets/approximatelyEqual.md
index e93864536..88773c163 100644
--- a/snippets/approximatelyEqual.md
+++ b/snippets/approximatelyEqual.md
@@ -10,5 +10,5 @@ const approximatelyEqual = (v1, v2, epsilon = 0.001) => Math.abs(v1 - v2) < epsi
 ```
 
 ```js
-approximatelyEqual(Math.PI / 2.0 , 1.5708); // true
+approximatelyEqual(Math.PI / 2.0, 1.5708); // true
 ```