0065【Edabit ★☆☆☆☆☆】【字符串长度的是奇数还是偶数】Is the String Odd or Even?

conditions strings validation

Instructions
Examples
oddOrEven("apples") // true
// The word "apples" has 6 characters.
// 6 is an even number, so the program outputs true.
oddOrEven("pears") // false
// "pears" has 5 letters, and 5 is odd.
// Therefore the program outputs false.
oddOrEven("cherry") // true
Notes
  • N/A
Solutions
function oddOrEven(s) {
	return s.length % 2 == 0;
}
TestCases
let Test = (function(){
    return {
        assertEquals:function(actual,expected){
            if(actual !== expected){
                let errorMsg = `actual is ${actual},${expected} is expected`;
                throw new Error(errorMsg);
            }
        },
        assertSimilar:function(actual,expected){
            if(actual.length != expected.length){
                throw new Error(`length is not equals, ${actual},${expected}`);
            }
            for(let a of actual){
                if(!expected.includes(a)){
                    throw new Error(`missing ${a}`);
                }
            }
        }
    }
})();
Test.assertEquals(oddOrEven("apples"), true)
Test.assertEquals(oddOrEven("banana"), true)
Test.assertEquals(oddOrEven("cherry"), true)
Test.assertEquals(oddOrEven("mango"), false)
Test.assertEquals(oddOrEven("peach"), false)
Test.assertEquals(oddOrEven("pears"), false)
11-15 10:30