当前位置: 首页 > article >正文

0039【Edabit ★☆☆☆☆☆】【字符串长度比较】Compare Strings by Count of Characters

0039【Edabit ★☆☆☆☆☆】【比较字符串长度】Compare Strings by Count of Characters

conditions strings validation

Instructions

Create a function that takes two strings as arguments and return either true or false depending on whether the total number of characters in the first string is equal to the total number of characters in the second string.

Examples
comp("AB", "CD") // true
comp("ABC", "DE") // false
comp("hello", "edabit") // false
Notes
  • Don’t forget to return the result.
  • If you get stuck on a challenge, find help in the Resources tab.
  • If you’re really stuck, unlock solutions in the Solutions tab.
Solutions
function comp(str1, str2) {
    return str1.length == str2.length ;
}
TestCases
function comp(str1, str2) {
    return str1.length == str2.length ;
}

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(comp("AB", "CD"), true)
Test.assertEquals(comp("ABC", "DE"), false)
Test.assertEquals(comp("hello", "edabit"), false)
Test.assertEquals(comp("meow", "woof"), true)
Test.assertEquals(comp("jrnvjrnnt", "cvjknfjvmfvnfjn"), false)
Test.assertEquals(comp("jkvnjrt", "krnf"), false)
Test.assertEquals(comp("Facebook", "Snapchat"), true)

http://www.kler.cn/a/104992.html

相关文章:

  • 一文搞懂比特币的原理
  • CICD 流程学习(五)Jenkins后端工程构建
  • AlDente Pro for Mac: 掌控电池充电的终极解决方案
  • SpringBoot运行流程源码分析------阶段三(Spring Boot外化配置源码解析)
  • Spring Boot Endpoints:端点
  • 渲染对电脑伤害多大?怎么避免对本地电脑的损害?
  • 第2篇 机器学习基础 —(2)分类和回归
  • Gdb调试
  • 设计模式:命令模式(C#、JAVA、JavaScript、C++、Python、Go、PHP)
  • web浏览器端实现语音转文字或文字转语音
  • c++ vscode cmake debug for mac
  • 汽车4S店如何在数字化管理下,提高市场竞争力
  • 本地新建项目如何推到码云上去
  • Spring Security系例—漏洞防御
  • 解决javascript报错:SyntaxError: Invalid Unicode escape sequence
  • C++(Qt)软件调试---线程死锁调试(15)
  • C++内存管理:其七、标准库中的allocator
  • linux中断下文工作队列之共享工作队列(中断四)
  • 【RTT驱动框架分析】- 队列DataQueue源码分析
  • RHCE---Shell基础 2