Yet another set of utilities to do "functional programming" on JavaScript Objects.
You can find many other versions of these online, but I like mine better :-).
Basically, allows you to use the ES6 array methods like map() and reduce() on objects.
Maybe you will find this useful. I mainly put it on GitHub so I can easily cut and paste these into other code.
All methods take the object as the first argument, and the user function (or "predicate") to be applied as the 2nd.
The method will loop over the key/value pairs in the object, as determined by Object.keys(theObject).
The user function will usually be called with three arguments, much like the array versions.
- The value
- the key (for the corresponding array versions, this is the index)
- the entire object
For reduce() and reduceRight(), the user function takes an additional acc` first argument.
Tests if every key/value pair passes predicate(value, key, object). Returns true or false, and will "short-circuit".
Finds the first key/value pair that passes predicate(value, key, object).
- returns it as an array: [key, value]
Creates a new object with (shallow) copies of all key/value pairs that pass predicate(value, key, object).
Calls fn(value, key, object) for every key/value pair.
Returns a new result object, with result[key] = fn(object[key], key, object).
Tests if any key/value pair passes predicate(value, key, object). Returns true or false, and will "short-circuit".
