Skip to content

Commit 9f70ce7

Browse files
committed
Use a map to easier show the increments
1 parent 6706767 commit 9f70ce7

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

src/utilities/roundUpToIncrement.ts

+13-32
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,19 @@ export function roundUpToIncrement(value: number, increment?: number): number {
99
return roundedUp
1010
}
1111

12-
function getSmallestIncrement(value: number): number {
13-
if (value < 10) {
14-
return 10
15-
}
16-
17-
if (value < 25) {
18-
return 5
19-
}
20-
21-
if (value < 100) {
22-
return 10
23-
}
24-
25-
if (value < 150) {
26-
return 25
27-
}
28-
29-
if (value < 500) {
30-
return 50
31-
}
32-
33-
if (value < 1000) {
34-
return 100
35-
}
36-
37-
if (value < 10000) {
38-
return 1000
39-
}
12+
const maxValueIncrementMap: Record<number, number> = {
13+
25: 5,
14+
100: 10,
15+
150: 25,
16+
500: 50,
17+
1000: 100,
18+
10000: 1000,
19+
100000: 100000,
20+
Infinity: 1000000,
21+
}
4022

41-
if (value < 100000) {
42-
return 10000
43-
}
23+
function getSmallestIncrement(value: number): number {
24+
const incrementKey = Object.keys(maxValueIncrementMap).map(Number).find(maxValue => value < maxValue)!
4425

45-
return 100000
26+
return maxValueIncrementMap[incrementKey]
4627
}

0 commit comments

Comments
 (0)