Skip to content

Instantly share code, notes, and snippets.

View neharkarvishal's full-sized avatar

Vishal Neharkar neharkarvishal

View GitHub Profile
/**
* 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.
*/
/**
* 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().
*/
/**
* 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).
*/
/**
* 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.
*/