Takes an array and modifies it by either updating the object matched by the predicate, or inserting a new object:
upsert(array, test, object)
var upsert = require('upsert')
upsert(
arrayOfPeople,
function(person) {
return 'goodall' === person.name;
},
{
name: 'dr goodall',
degree: 'doctorate'
});
If test
doesn't return true for anything in array
, object
will be pushed onto array
. If test
matches
something in array
, then object
will be extended onto what was matched.
If there are multiple matches, only the first one is modified.
The array that is passed in is modified, and it is also - for convenience - returned.
To use in a project:
To run the tests, git clone
, npm install
, npm test
.