2813. To Be Or Not To Be
My accepted JavaScript solution to LeetCode problem 2813, To Be Or Not To Be, running in 39ms.
- Difficulty: Easy
- JavaScript
- Runtime 39ms
- Memory 53.9MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
JavaScript
Accepted on LeetCode — runtime 39ms, memory 53.9MB, accepted 2025-12-31.
/**
* @param {string} val
* @return {Object}
*/
var expect = function(val) {
return {
toBe: function(val2) {
if (val === val2) return true;
throw new Error("Not Equal");
},
notToBe: function(val2) {
if (val !== val2) return true;
throw new Error("Equal");
}
};
};
/**
* expect(5).toBe(5); // true
* expect(5).notToBe(5); // throws "Equal"
*/