Skip to content

Instantly share code, notes, and snippets.

@eezhal92
Last active July 19, 2017 15:23
Show Gist options
  • Save eezhal92/1712401006db47d0b00c22d9f1d4ef8a to your computer and use it in GitHub Desktop.
Save eezhal92/1712401006db47d0b00c22d9f1d4ef8a to your computer and use it in GitHub Desktop.
findMinMax.js
const pluck = key => list => list[key];
const pluckX = pluck('x');
const pluckY = pluck('y');
const groupXAndY = list => {
return {
listX: list.map(pluckX),
listY: list.map(pluckY),
};
}
export const findMinMax = points => {
const { listX, listY } = groupXAndY(points);
return {
minX: Math.min(Number.MAX_SAFE_INTEGER, ...listX),
maxX: Math.max(Number.MIN_SAFE_INTEGER, ...listX),
minY: Math.min(Number.MAX_SAFE_INTEGER, ...listY),
maxY: Math.max(Number.MIN_SAFE_INTEGER, ...listY),
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment