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

Update sumObjects to coerce numeric strings, preserve Arrays in return #324

Merged
merged 4 commits into from
May 16, 2024

Conversation

brandonmcconnell
Copy link
Contributor

@brandonmcconnell brandonmcconnell commented Apr 5, 2024

Changed made

  • Update sumObjects to automatically coerce numeric strings to numbers
  • Update sumObjects to return the summed values as an Array if all processed items are arrays

Copy link

changeset-bot bot commented Apr 5, 2024

🦋 Changeset detected

Latest commit: e369f8d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte-ux Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Apr 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
svelte-ux 🛑 Canceled (Inspect) May 16, 2024 11:48am

Copy link
Owner

@techniq techniq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @brandonmcconnell. Could you run pnpm format to fix the lint issues (prettier formatting) which will allow the CI tests to run, and add a few more tests...

  • Using the accessor as a function (ex. sumObjects(data, d => ...))
  • Using the accessor as a string (ex. sumObjects(data, 'value'))
    • data: [{ foo: { value: 123 }, bar: { value: 234 } }, { foo: { value: 987 }, ... }]
  • Data as an array of arrays

Thanks!

const result = rollup(
items.flatMap((x) => entries(x ?? {})),
(values) => sum(values, (d) => {
const value = Number(getProp(d[1]));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should also get the key as the second argument (d[0] and maybe the whole object as the third (d), similar to just-map-values

@techniq techniq merged commit 2779a4b into techniq:main May 16, 2024
2 of 3 checks passed
@github-actions github-actions bot mentioned this pull request May 16, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants