Skip to content

Allow sending objects as items #21

@cowchimp

Description

@cowchimp

Hi.

Thanks for this library.
I have a suggestion for an additional feature which I think will be useful.

Right now you have to pass in an array of arrays.
That means that if I have an object that contains a property for the "value" and another property for the "weight", I would have to transform it to that temporary array.
What if instead I could do this:

let input = [
  {
    somePropertyNameForValue: 100,
    somePropertyNameForWeight: 2,
    someOtherPropertyNotRelevant: 'Foo'
  },
  {
    somePropertyNameForValue: 50,
    somePropertyNameForWeight: 4,
    someOtherPropertyNotRelevant: 'Bar'
  },
  {
    somePropertyNameForValue: 25,
    somePropertyNameForWeight: 1,
    someOtherPropertyNotRelevant: 'Baz'
  },
];

let mean =  weightedMean(input, x => somePropertyNameForValue, x => x.somePropertyNameForWeight);

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions