拼多多前端一面编程题

这种题一直没有什么思路,求大佬指点啊!!!

#拼多多##前端##笔试题目#
全部评论
尝试了一下: function getValueByPath(a, str) { const keys = str.split('.'); try { const result = keys.reduce((acc, current) => { if (/.+\[\d+\]/g.test(current)) { const matchs = (/^(.+)\[(\d+)\]/g).exec(current); const arr = acc[matchs[1]]; const index = matchs[2]; return arr[index]; } const key = current; return acc[key]; }, a); return result; } catch (error) { return undefined } } const x = { a: { b: [{ c: 1 }] } }; const y = []; console.log(getValueByPath(x, 'a.b[0].c')); console.log(getValueByPath(y, 'a.b[0].c')); 顺便问下,你什么时候投的以及什么时候笔试的,为什么我还没收到面试通知。
点赞 回复 分享
发布于 2018-08-09 12:08
......
点赞 回复 分享
发布于 2018-08-10 12:56
麻烦问一下几号笔试的
点赞 回复 分享
发布于 2018-08-10 11:37
第二个参数用按符号.分割 str.split()会变成一个数组 for loop这个数组 每个元素作为当前对象的属性 如x[a] 存在值继续往第下 不存在就return undefined 退出
点赞 回复 分享
发布于 2018-08-09 11:32

相关推荐

买蜜雪也用卷:我觉得应该没有哪个人敢说自己熟练使用git,代码分支一复杂还是得慢慢寻思一下的,不过基本的拉代码提交代码还有分支什么的是应该会
点赞 评论 收藏
分享
评论
1
15
分享

创作者周榜

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