Created
February 22, 2021 10:44
-
-
Save LeaveNhA/8ef052ab7a31245c51ac3f25cb5bd896 to your computer and use it in GitHub Desktop.
Javascript Number Precision Equaliser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Developed by Seçkin KÜKRER (@LeaveNhA) for Vue Turkiye Community! | |
// Downs the numbers precision to the lowest precision number of the vector. | |
const precisionDowner = ns => | |
([v => v.map(n => ({count: (n + '').length, value: n})), | |
v => v.sort((a,b) => a.count > b.count), | |
v => ({meta: {minCount: v[0].count}, value: v}), | |
md => md.value.map(n => Number.parseFloat(n.value).toPrecision(md.meta.minCount)) | |
] | |
.reduce((acc, f) => f(acc), ns)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment