Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // eslint-disable-next-line
- import { makePoint, getX, getY, quadrant, toString as pointToString } from 'hexlet-points';
- // eslint-disable-next-line
- import { cons, car, cdr, toString as pairToString } from 'hexlet-pairs';
- // BEGIN (write your solution here)
- const makeRectangle = (startPoint, width, height) => {
- const sides = cons(width, height);
- return cons(startPoint, sides);
- };
- const startPoint = rectangle => car(rectangle);
- const width = rectangle => car(cdr(rectangle));
- const height = rectangle => cdr(cdr(rectangle));
- const square = rectangle => car(cdr(rectangle)) * cdr(cdr(rectangle));
- const perimeter = rectangle => 2 * (car(cdr(rectangle)) + cdr(cdr(rectangle)));
- const containsTheOrigin = rectangle => {
- const startPoint = car(rectangle);
- const startX = getX(startPoint);
- const startY = getY(startPoint);
- const secondPoint = makePoint(startX + width(rectangle), startY);
- const thirdPoint = makePoint(startX + width(rectangle), startY - height(rectangle));
- const endPoint = makePoint(startX, startY - height(rectangle));
- return quadrant(startPoint) !== quadrant(secondPoint) && quadrant(startPoint) !== quadrant(endPoint);
- };
- export { makeRectangle, startPoint, width, height, square, perimeter, containsTheOrigin };
- // END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement