This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* partitionArray.js | |
* tags: { JavaScript, Array, Object, Function } | |
* Groups the elements into two arrays, depending on the provided function's | |
* truthiness for each element. | |
* Use Array.prototype.reduce() to create an array of two arrays. | |
* Use Array.prototype.push() to add elements for which fn returns true to the | |
* first array and elements for which fn returns false to the second one. | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* zipObject.js | |
* tags: { JavaScript, Array, Object } | |
* Given an array of valid property identifiers and an array of values, | |
* return an object associating the properties to the values. | |
* Since an object can have undefined values but not undefined property | |
* pointers, the array of properties is used to decide the structure of | |
* the resulting object using Array.prototype.reduce(). | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* removeArrayElements.js | |
* tags: { JavaScript, Array } | |
* Removes elements from an array for which the given function returns false. | |
* Use Array.prototype.filter() to find array elements that return truthy | |
* values and Array.prototype.reduce() to remove elements using | |
* Array.prototype.splice(). The func is invoked with three | |
* arguments (value, index, array). | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* pipeAsyncFunctions.js | |
* tags: { JavaScript, Adapter, Function, Promise } | |
* Performs left-to-right function composition for asynchronous functions. | |
* Use Array.prototype.reduce() with the spread operator (...) to perform | |
* left-to-right function composition using Promise.then(). The functions can | |
* return a combination of: simple values, Promise's, or they can be defined as | |
* async ones returning through await. All functions must be unary. | |
*/ |
NewerOlder