Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow sending objects as items #21

Open
cowchimp opened this issue Sep 30, 2017 · 1 comment
Open

Allow sending objects as items #21

cowchimp opened this issue Sep 30, 2017 · 1 comment

Comments

@cowchimp
Copy link

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!

@satazor
Copy link
Member

satazor commented Sep 30, 2017

I understood your suggestion but, unless the array is really huge, you can just do a .map as you said to generate the input. I would like to keep this module simple.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants