Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

merge-most-frequent

oprogramador8MIT1.1.13

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

merge, most, frequent, assign

readme

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