您当前的位置: 首页 >  前端

暂无认证

  • 0浏览

    0关注

    92582博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

程序员(web前端开发工程师)、手机号码、二进制、十进制、构造函数、substr、parseInt、prototype、length

发布时间:2022-02-24 15:04:40 ,浏览量:0

function PhoneNumber() { this.arrayNumber = ['110', '10', '111', '11', '0', '1000', '100', '1', '101', '1001']; this.i = 0; this.len = 0; this.result = ''; } PhoneNumber.prototype.calculation = function (params = '') { this.len = params.length; if (!this.len) return '长度不能为空!'; if (!/^\d+$/.test(Number(params))) return '请输入纯数字!'; for (; this.i < this.len;)(this.result += parseInt(this.arrayNumber[params[this.i]], 2), this.i++); this.result = `${this.result.substr(0, 3)} ${this.result.substr(3, 4)} ${this.result.substr(7)}`; return this.result; } let phoneNumber = new PhoneNumber(); console.log(phoneNumber.calculation('78159051872')); 
关注
打赏
1653961664
查看更多评论
立即登录/注册

微信扫码登录

0.7607s