I have these 10 variables already declared and they each contain a float value.
Is there any way to apply the function toFixed(prec)
with prec
as the parameter to all these variables with a shorter code? Using an array or something like that?
x1 = x1.toFixed(prec);
x2 = x2.toFixed(prec);
y1 = y1.toFixed(prec);
y2 = y2.toFixed(prec);
a1 = a1.toFixed(prec);
a2 = a2.toFixed(prec);
b1 = b1.toFixed(prec);
b2 = b2.toFixed(prec);
c1 = c1.toFixed(prec);
c2 = c2.toFixed(prec);
2
Answers
Yes, you should keep all these parameters in object (as associative array in other language), than you can simply loop that object.
Put the variables into an array, map it and destructure: