Methods
(inner) applyByProp(func, key, val, list) → {Array.<Object>}
Higher order function to apply a property matching predicate to list transformation functions like filter or reject
Parameters:
Name | Type | Description |
---|---|---|
func |
function | function to apply prop matching predicate to |
key |
String | key to match with the specified value |
val |
* | value to match on the specified key |
list |
Array.<Object> | list against which to apply function |
Returns:
a list derived from original list according to func
- Type
- Array.<Object>
(inner) containsAll(checkArr, searchArr) → {Boolean}
Takes two lists of values, returns true if all the values in the first array are present in the second array
Parameters:
Name | Type | Description |
---|---|---|
checkArr |
Array | list of values to check for |
searchArr |
Array | list of values to search in |
Returns:
- Type
- Boolean
Example
const vals = [1, 2, 3]
const containsVals = containsAll(vals)
containsVals([1, 2, 3, 4, 5]) //=> true
containsVals([1, 2, 4, 5, 6]) // false
(inner) dropByProp(key, val) → {function}
Curried function to drop items from a list of objects according to the value of a specified property
Parameters:
Name | Type | Description |
---|---|---|
key |
String | key to match with the specified value |
val |
String | value to match on the specified key |
Returns:
- Type
- function
(inner) filterById(val, list) → {Array.<Object>}
Curried function to filter a list of objects by id property
Parameters:
Name | Type | Description |
---|---|---|
val |
* | value to match against id key |
list |
Array.<Object> | list to filter |
Returns:
filtered list of objects
- Type
- Array.<Object>
Example
const friends = [
{ name: 'trogdor', id: 'dragon' },
{ name: 'booseph', id: 'dragon' },
{ name: 'kitty', id: 'kitty' },
]
filterById('dragon', friends)
//=> [ { name: 'trogdor', id: 'dragon' }, { name: 'booseph', id: 'dragon' } ]
(inner) filterByName(val, list) → {Array.<Object>}
Curried function to filter a list of objects by name property
Parameters:
Name | Type | Description |
---|---|---|
val |
* | value to match against name key |
list |
Array.<Object> | list to filter |
Returns:
filtered list of objects
- Type
- Array.<Object>
Example
const friends = [
{ name: 'trogdor', type: 'dragon' },
{ name: 'trogdor', type: 'giant-dragon' },
{ name: 'kitty', type: 'kitty' },
]
filterByName('trogdor', friends)
//=> [ { name: 'trogdor', type: 'dragon' }, { name: 'trogdor', type: 'giant-dragon' } ]
(inner) filterByProp(key, val, list) → {Array.<Object>}
Curried function to filter a list of objects according to the value of a specified property
Parameters:
Name | Type | Description |
---|---|---|
key |
String | key to match with the specified value |
val |
* | value to match on the specified key |
list |
Array.<Object> | against which to apply function |
Returns:
filtered list of objects
- Type
- Array.<Object>
Example
const friends = [
{ name: 'trogdor', type: 'dragon' },
{ name: 'booseph', type: 'dragon' },
{ name: 'kitty', type: 'kitty' },
]
filterByProp('type', 'dragon', friends)
//=> [ { name: 'trogdor', type: 'dragon' }, { name: 'booseph', type: 'dragon' } ]
(inner) findByProp(key, val, list) → {Object}
Curried function to find the first object in a list where the value of a specified property matches the given value
Parameters:
Name | Type | Description |
---|---|---|
key |
String | key to match with the specified value |
val |
* | value to match on the specified key |
list |
Array.<Object> | list of objects to search in |
Returns:
the first object in list where the given property matches the given value
- Type
- Object
Example
const friends = [
{ name: 'trogdor', name: 'dragon' },
{ name: 'booseph', name: 'dragon' },
{ name: 'kitty', name: 'kitty' },
]
findByProp('name', 'trogdor', friends)
//=> [ { name: 'trogdor', name: 'dragon' } ]
(inner) mergeListsByProp(prop, source, search)
Takes a property name, a source list and a search list, returns the result of merging each element from the source list with the first object from the search list where the value of the given property is equal
Parameters:
Name | Type | Description |
---|---|---|
prop |
String | name of property merge by |
source |
Array.<Object> | array to search for matches in |
search |
Array.<Object> | array to project result from |
Returns:
{Object[] list of objects that contain all properties from each list where the given property was equal
Example
const sourceArr = [{ id: 1, likes: 'gibbons' }, { id: 3, likes: 'pasta' }]
const searchArr = [
{ id: 1, firstName: 'Bob', lastName: 'Franklin' },
{ id: 2, firstName: 'Rob', lastName: 'Lob' },
{ id: 3, firstName: 'Tob', lastName: 'Lob' },
]
mergeListsByProp('id', sourceArr, searchArr)
//=> [
// { id: 1, likes: 'gibbons', firstName: 'Bob', lastName: 'Franklin' },
// { id: 3, likes: 'pasta', firstName: 'Tob', lastName: 'Lob' },
//]