Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. // eslint-disable-next-line
  2. import { makePoint, getX, getY, quadrant, toString as pointToString } from 'hexlet-points';
  3. // eslint-disable-next-line
  4. import { cons, car, cdr, toString as pairToString } from 'hexlet-pairs';
  5.  
  6. // BEGIN (write your solution here)
  7. const makeRectangle = (startPoint, width, height) => {
  8. const sides = cons(width, height);
  9. return cons(startPoint, sides);
  10. };
  11.  
  12. const startPoint = rectangle => car(rectangle);
  13.  
  14. const width = rectangle => car(cdr(rectangle));
  15.  
  16. const height = rectangle => cdr(cdr(rectangle));
  17.  
  18. const square = rectangle => car(cdr(rectangle)) * cdr(cdr(rectangle));
  19.  
  20. const perimeter = rectangle => 2 * (car(cdr(rectangle)) + cdr(cdr(rectangle)));
  21.  
  22. const containsTheOrigin = rectangle => {
  23. const startPoint = car(rectangle);
  24. const startX = getX(startPoint);
  25. const startY = getY(startPoint);
  26. const secondPoint = makePoint(startX + width(rectangle), startY);
  27. const thirdPoint = makePoint(startX + width(rectangle), startY - height(rectangle));
  28. const endPoint = makePoint(startX, startY - height(rectangle));
  29.  
  30. return quadrant(startPoint) !== quadrant(secondPoint) && quadrant(startPoint) !== quadrant(endPoint);
  31. };
  32.  
  33. export { makeRectangle, startPoint, width, height, square, perimeter, containsTheOrigin };
  34. // END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement