题解 | #判断是否符合指定格式#

判断是否符合指定格式

http://www.nowcoder.com/practice/eb86f08c478749868a01861f5ddad28b

function matchesPattern(str) {
let arr = str.split('-')
let result = true
arr.forEach((item, index) => {
if (index === 0 || index === 1) {
if (item.length !== 3) {
result = false
return
}
}
if (index === 2) {
if (item.length !== 4) {
result = false
return
}
}
if (isNaN(Number(item))) {
result = false
}
})
return result
}

全部评论

相关推荐

04-11 23:51
门头沟学院 Java
坚定的芭乐反对画饼_许愿Offer版:人人都能过要面试干嘛,发个美团问卷填一下,明天来上班不就好了
点赞 评论 收藏
分享
03-19 10:07
已编辑
广东药科大学 golang
Yki_:你倒是进一个面啊
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务