题目:2704.相等还是不相等

题目来源:

        leetcode题目,网址:2704. 相等还是不相等 - 力扣(LeetCode)

解题思路:

       按要求模拟即可。

解题代码:

/**
 * @param {string} val
 * @return {Object}
 */
var expect = function(val) {
    return {
        toBe:function(val1){
            if(val1===val){
                return true;
            }else{
                throw new Error("Not Equal");
            }
        },
        notToBe:function(val2){
            if(val2!==val){
                return true;
            }else{
                throw new Error("Equal");
            }
        }
    }
};



/**
 * expect(5).toBe(5); // true
 * expect(5).notToBe(5); // throws "Equal"
 */
 
  

总结:

        无官方题解。

        需要使用 this 或者直接下载 return 里;不能直接return "Equal",要 抛出错误;== 是判断值是否相等,===判断 值和类型是否相等。


你可能感兴趣的:(#,二刷,leetcode,JavaScript)