Miss any of our Open RFC calls?Watch the recordings here! »

merge-most-frequent

1.0.13 • Public • Published

merge-most-frequent

MIT License Build Status

NPM status

JS library for merging objects like Object.assign but it takes the most frequent value instead of the last value

how to install?

yarn add merge-most-frequent or npm i --save merge-most-frequent

how to use?

const mergeMostFrequent = require('merge-most-frequent').default;
/*
 * or:
 * import mergeMostFrequent from 'merge-most-frequent';
 */
 
const objects = [
  {
    foo: 'foo1',
    bar: 'bar1',
    baz: 'baz1',
  },
  {
    foo: 'foo1',
    bar: 'bar2',
    baz: 'baz2',
  },
  {
    foo: 'foo2',
    bar: 'bar2',
    baz: 'baz1',
  },
];
 
expect(mergeMostFrequent(objects)).to.deep.equal({
  foo: 'foo1',
  bar: 'bar2',
  baz: 'baz1',
});

how does it work?

  • for each field, it returns the most frequent value
  • if many values occur for the same number of times, the most recently used value wins
  • a field has to occur in at least one of the objects, to be included in the result

Install

npm i merge-most-frequent

DownloadsWeekly Downloads

16

Version

1.0.13

License

MIT

Unpacked Size

4.05 kB

Total Files

4

Last publish

Collaborators

  • avatar