2704. To Be Or Not To Be
All prompts are owned by LeetCode. To view the prompt, click the title link above.
First completed : July 09, 2024
Last updated : July 10, 2024
Related Topics : N/A
Acceptance Rate : 62.52 %
class helper {
constructor(val) {
this.val = val;
}
toBe(n) {
if (n !== this.val) throw new Error('Not Equal');
return true;
}
notToBe(n) {
if (n === this.val) throw new Error('Equal');
return true;
}
}
/**
* @param {string} val
* @return {Object}
*/
var expect = function(val) {
return new helper(val);
};
/**
* expect(5).toBe(5); // true
* expect(5).notToBe(5); // throws "Equal"
*/
/**
* @param {string} val
* @return {Object}
*/
var expect = function(val) {
let obj = {
toBe: function(n) {
if (n !== val) throw new Error('Not Equal');
return true;
},
notToBe: function(n) {
if (val === n) throw new Error('Equal');
return true;
}
}
return obj;
};
/**
* expect(5).toBe(5); // true
* expect(5).notToBe(5); // throws "Equal"
*/