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

判断是否符合指定格式

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
}

全部评论

相关推荐

想进开水团喝开水:哦 给我一个 就算你真拿到牛友也会为你开心的
点赞 评论 收藏
分享
12-15 11:27
门头沟学院 Java
哇哇的菜鸡oc:所有人不要理会,就好了,后面他就知道怎么回事了,只能说有的时候市场都是被宰的人搞坏的
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务