Skip to content

Commit ad4e7fa

Browse files
authored
Create to-be-or-not-to-be.ts
1 parent 8dd5d54 commit ad4e7fa

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

TypeScript/to-be-or-not-to-be.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Time: O(1)
2+
// Space: O(1)
3+
4+
type ToBeOrNotToBe = {
5+
toBe: (val: any) => boolean;
6+
notToBe: (val: any) => boolean;
7+
};
8+
9+
function expect(val: any): ToBeOrNotToBe {
10+
return {
11+
toBe: (val2: any): boolean => {
12+
if (val !== val2) {
13+
throw new Error("Not Equal");
14+
}
15+
return true;
16+
},
17+
notToBe: (val2: any): boolean => {
18+
if (val === val2) {
19+
throw new Error("Equal");
20+
}
21+
return true;
22+
}
23+
};
24+
};

0 commit comments

Comments
 (0)