0028【Edabit ★☆☆☆☆☆】Equality Check

编程入门 行业动态 更新时间:2024-10-27 04:34:03

0028【<a href=https://www.elefans.com/category/jswz/34/1666502.html style=Edabit ★☆☆☆☆☆】Equality Check"/>

0028【Edabit ★☆☆☆☆☆】Equality Check

0028【Edabit ★☆☆☆☆☆】Equality Check

language_fundamentals logic validation

Instructions

In this challenge, you must verify the equality of two different values given the parameters a and b.

Both the value and type of the parameters need to be equal. The possible types of the given parameters are:

  • Numbers
  • Strings
  • Booleans (false or true)
  • Special values: undefined, null and NaN

What have you learned so far that will permit you to do two different checks (value and type) with a single statement?

Implement a function that returns true if the parameters are equal, and `false`` if they are not.

Examples
checkEquality(1, true) // false
// A number and a boolean: the value and type are different.checkEquality(0, "0") // false
// A number and a string: the type is different.checkEquality(1,  1) // true
// A number and a number: the type and value are equal.
Notes
  • N/A
Solutions
function checkEquality(a, b) {return a === b ;
}
TestCases
let Test = (function(){return {assertEquals:function(actual,expected){if(actual !== expected){let errorMsg = `actual is ${actual},${expected} is expected`;throw new Error(errorMsg);}}}
})();Test.assertEquals(checkEquality(1, true), false, "Example #1")
Test.assertEquals(checkEquality(0, "0"), false, "Example #2")
Test.assertEquals(checkEquality(1, 1), true, "Example #3")
Test.assertEquals(checkEquality(0, ""), false)
Test.assertEquals(checkEquality(1, "1"), false)
Test.assertEquals(checkEquality(0, false), false)
Test.assertEquals(checkEquality(NaN, NaN), false)
Test.assertEquals(checkEquality(null, undefined), false)
Test.assertEquals(checkEquality(undefined, undefined), true)
Test.assertEquals(checkEquality(false, null), false)

更多推荐

0028【Edabit ★☆☆☆☆☆】Equality Check

本文发布于:2023-12-03 23:07:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1658743.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Edabit   Check   Equality

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!