jashkenas / jashkenas/underscore
Feature request: _.deleteWhere
- Dominant language
- JavaScript
- Stars
- 27.3k
- Forks
- 5.4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 1
Description
Currently having array of objects, to delete one of them I need to write:
``` javascript
var collection = [{id: 1}, {id: 3}];
var objectToRemove = _.findWhere(collection, function (obj) { return obj.id === 3 });
var objectIndex = collection.indexOf(objectToRemove);
collection.splice(objectIndex, 1);
```
It would be nice to have in underscore something like:
``` javascript
_.deleteWhere(collection, {id: 2})
```
If you find this useful I can try to implement it and send a PR.
Contributor guide
Research direction
No file or test is named. Start with the issue's findWhere, indexOf, and splice example and inspect the existing collection helpers; the API's matching and mutation behavior need agreement before implementation. Done means an accepted deleteWhere design plus tests covering the requested object collection case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100