File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 407
407
2677|[ Chunk Array] ( ./2677-chunk-array.js ) |Easy|
408
408
2695|[ Array Wrapper] ( ./2695-array-wrapper.js ) |Easy|
409
409
2703|[ Return Length of Arguments Passed] ( ./2703-return-length-of-arguments-passed.js ) |Easy|
410
+ 2704|[ To Be Or Not To Be] ( ./2704-to-be-or-not-to-be.js ) |Easy|
410
411
2705|[ Compact Object] ( ./2705-compact-object.js ) |Medium|
411
412
2715|[ Timeout Cancellation] ( ./2715-timeout-cancellation.js ) |Easy|
412
413
2721|[ Execute Asynchronous Functions in Parallel] ( ./2721-execute-asynchronous-functions-in-parallel.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 2704. To Be Or Not To Be
3
+ * https://leetcode.com/problems/to-be-or-not-to-be/
4
+ * Difficulty: Easy
5
+ *
6
+ * Write a function expect that helps developers test their code. It should take in any
7
+ * value val and return an object with the following two functions.
8
+ *
9
+ * - toBe(val) accepts another value and returns true if the two values === each other.
10
+ * If they are not equal, it should throw an error "Not Equal".
11
+ * - notToBe(val) accepts another value and returns true if the two values !== each
12
+ * other. If they are equal, it should throw an error "Equal".
13
+ */
14
+
15
+ /**
16
+ * @param {string } val
17
+ * @return {Object }
18
+ */
19
+ var expect = function ( val ) {
20
+ const compareHelper = ( error , fn ) => {
21
+ if ( fn ( ) ) throw new Error ( error ) ;
22
+ return true ;
23
+ } ;
24
+ return {
25
+ toBe : input => compareHelper ( 'Not Equal' , ( ) => input !== val ) ,
26
+ notToBe : input => compareHelper ( 'Equal' , ( ) => input === val ) ,
27
+ } ;
28
+ } ;
You can’t perform that action at this time.
0 commit comments