Skip to content

Commit

Permalink
Install lodash to define range
Browse files Browse the repository at this point in the history
  • Loading branch information
nvlaarhoven committed Apr 23, 2020
1 parent bbae8e9 commit e64f990
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
8 changes: 6 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@
"dependencies": {
"@types/classnames": "^2.2.0",
"@types/cookie": "^0.3.1",
"@types/lodash": "^4.14.150",
"@types/random-seed": "^0.3.2",
"@types/react": ">= 15",
"@types/react-dom": ">= 15",
"@types/react-transition-group": "^1.1.4",
"classnames": "^2.2.5",
"cookie": "^0.3.1",
"lodash": "^4.17.15",
"normalize.css": "^8.0.1",
"random-seed": "^0.3.0",
"react": ">= 15",
Expand Down
6 changes: 5 additions & 1 deletion src/ts/utils/slider.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { range } from 'lodash';

export const getNumberOfSteps = (step: number, min: number, max: number) => {
const totalRange = Math.abs(max - min);
return Math.floor(totalRange / step) + 1;
Expand All @@ -9,7 +11,9 @@ export const getStepSeries = (
max: number
): ReadonlyArray<number> => {
const stepCount = getNumberOfSteps(step, min, max);
const series = [...Array(stepCount)].map((_value: number, index: number) => min + index * step);
const series = range(stepCount).map(
(_VALUE: number, index: number) => min + index * step
);
// NOTE: if the last value in the series is less than the max we need another step in order to be able to select it
return series[series.length - 1] < max ? [...series, max] : series;
};
Expand Down

0 comments on commit e64f990

Please sign in to comment.