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
andb
.Both the value and type of the parameters need to be equal. The possible types of the given parameters are:
- Numbers
- Strings
- Booleans (
false
ortrue
)- Special values:
undefined
,null
andNaN
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
发布评论