Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. export function Thing {
  2. constructor(one, two) {
  3. this.one = one;
  4. this.two = two;
  5. }
  6. }
  7.  
  8. let t1 = new Thing(1, 2);
  9. let t2 = new Thing('one', 'two');
  10. let t3 = addThings(t1, t2); // {one: '1 & one', two: '2 & two'}
  11.  
  12. function addThings(lhs, rhs) {
  13. let one, two;
  14. if (lhs.one && typeof lhs.one === 'number' && rhs.one && typeof rhs.one ==v 'number') {
  15. one = lhs.one + rhs.one;
  16. } else {
  17. one = `${lhs.one} & ${rhs.one}`
  18. }
  19. if (lhs.two && typeof lhs.two === 'number' && rhs.two && typeof rhs.two === 'number') {
  20. two = lhs.two + rhs.two;
  21. } else {
  22. two = `${lhs.two} & ${rhs.two}`;
  23. }
  24. return new Thing(one, two);
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement