javascript - Get the next decade after a given value -
what's best way next decade after given value in javascript. example:
for 9 10^1
200 10^3
1001 10^4
i need algorithm work negative numbers:
for -9 -10^1
200 -10^3
1001 -10^4
maybe i've misused term decade. mean next whole number that's raised power base 10. 9, that's 10^1. 200, that's 10^3 10^2 less 200...
you use logarithm of 10 , add 1 integer value power 10. may need save sign in advance.
console.log([9, 200, 1001, -9].map(v => (v >= 0 || -1) * math.pow(10, 1 + math.floor(math.log10(math.abs(v))))));
Comments
Post a Comment