Skip to content

Instantly share code, notes, and snippets.

@LeaveNhA
Created February 22, 2021 10:44
Show Gist options
  • Save LeaveNhA/8ef052ab7a31245c51ac3f25cb5bd896 to your computer and use it in GitHub Desktop.
Save LeaveNhA/8ef052ab7a31245c51ac3f25cb5bd896 to your computer and use it in GitHub Desktop.
Javascript Number Precision Equaliser
// 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