Skip to content

2704. To Be Or Not To Be 👍

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
type ToBeOrNotToBe = {
  toBe: (val: any) => boolean;
  notToBe: (val: any) => boolean;
};

function expect(val: any): ToBeOrNotToBe {
  return {
    toBe: function (val2: any) {
      if (val === val2) {
        return true;
      }
      throw 'Not Equal';
    },
    notToBe: function (val2: any) {
      if (val !== val2) {
        return true;
      }
      throw 'Equal';
    },
  };
}