-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy path2704-to-be-or-not-to-be.js
More file actions
28 lines (27 loc) · 910 Bytes
/
2704-to-be-or-not-to-be.js
File metadata and controls
28 lines (27 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/**
* 2704. To Be Or Not To Be
* https://leetcode.com/problems/to-be-or-not-to-be/
* Difficulty: Easy
*
* Write a function expect that helps developers test their code. It should take in any
* value val and return an object with the following two functions.
*
* - toBe(val) accepts another value and returns true if the two values === each other.
* If they are not equal, it should throw an error "Not Equal".
* - notToBe(val) accepts another value and returns true if the two values !== each
* other. If they are equal, it should throw an error "Equal".
*/
/**
* @param {string} val
* @return {Object}
*/
var expect = function(val) {
const compareHelper = (error, fn) => {
if (fn()) throw new Error(error);
return true;
};
return {
toBe: input => compareHelper('Not Equal', () => input !== val),
notToBe: input => compareHelper('Equal', () => input === val),
};
};