Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/akshatbhargava123/diff-ranges
JavaScript Package that return index ranges of different objects between two array of objects
https://github.com/akshatbhargava123/diff-ranges
Last synced: about 5 hours ago
JSON representation
JavaScript Package that return index ranges of different objects between two array of objects
- Host: GitHub
- URL: https://github.com/akshatbhargava123/diff-ranges
- Owner: akshatbhargava123
- Created: 2019-11-09T06:35:14.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-11-09T13:07:49.000Z (about 5 years ago)
- Last Synced: 2024-04-29T05:22:58.566Z (7 months ago)
- Language: JavaScript
- Size: 2.93 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# diff-ranges
JavaScript function that return index ranges of new objects in an array of objects and also return newly added objects.
## How to use?
### Import
```javascript
const { getDiffIndexRanges } = require('./diff-ranges');// OR
import { getDiffIndexRanges } from './diff-ranges';
```### Define your arrays (Example)
```javascript
const a = [
{
name: 'val1',
age: 20
},
{
name: 'val2',
age: 21
}
];const b = [
{
name: 'val1',
age: 20
},
{
name: 'val2',
age: 19
},
{
name: 'val3',
age: 21
},
{
name: 'val4',
age: 20
}
];
```### Use it
```javascript
const result = getDiffIndexRanges(a, b, (ai, bi) => ai.name === bi.name);
const indicesRanges = result.rangeIndices;
// [{ startRow: 2, endRow: 4 }]const newElements = result.newElements;
/*
[{
name: 'val3',
age: 21
},
{
name: 'val4',
age: 20
}]
*/
```### API
```javascript
getDiffIndexRanges(oldArray, newArray, comparatorFunction);
```