mirror of
https://github.com/He4eT/xecut-site.git
synced 2026-05-04 17:37:26 +00:00
filters: sumObjectValues
This commit is contained in:
parent
f985b00e2b
commit
83c1f47ace
1 changed files with 10 additions and 0 deletions
10
src/_filters/sumObjectValues.js
Normal file
10
src/_filters/sumObjectValues.js
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
/**
|
||||||
|
* Transform {a: 1, b: 2, c: 'skip'} to 3
|
||||||
|
* @param {Record<string, unknown>} obj
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
export const sumObjectValues = (obj) => {
|
||||||
|
return Object.values(obj)
|
||||||
|
.filter((x) => typeof x === 'number')
|
||||||
|
.reduce((sum, x) => sum + x, 0)
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue