Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export function Thing {
- constructor(one, two) {
- this.one = one;
- this.two = two;
- }
- }
- let t1 = new Thing(1, 2);
- let t2 = new Thing('one', 'two');
- let t3 = addThings(t1, t2); // {one: '1 & one', two: '2 & two'}
- function addThings(lhs, rhs) {
- let one, two;
- if (lhs.one && typeof lhs.one === 'number' && rhs.one && typeof rhs.one ==v 'number') {
- one = lhs.one + rhs.one;
- } else {
- one = `${lhs.one} & ${rhs.one}`
- }
- if (lhs.two && typeof lhs.two === 'number' && rhs.two && typeof rhs.two === 'number') {
- two = lhs.two + rhs.two;
- } else {
- two = `${lhs.two} & ${rhs.two}`;
- }
- return new Thing(one, two);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement