题解 | #简易深拷贝#

简易深拷贝

https://www.nowcoder.com/practice/3d436d07f5cb4b628a4dd7c12476cabe

{"html":"<!DOCTYPE html>\r\n<html>\r\n    <head>\r\n        <meta charset=utf-8>\r\n    </head>\r\n    <body>\r\n    \t\r\n        <script type=\"text/javascript\">\r\n            const _sampleDeepClone = target => {\r\n                // 补全代码\r\n                if(typeof target !== 'object' || !target) {\r\n                    return target;\r\n                }\r\n                const cpy = Array.isArray(target) ? [] : {};\r\n\r\n                for(let prop in target) {\r\n                    if(target.hasOwnProperty(prop)){\r\n                        if(typeof target[prop] === 'object') {\r\n                            cpy[prop] = _sampleDeepClone(target[prop])\r\n                        } else {\r\n                            cpy[prop] = target[prop]\r\n                        }\r\n                    }\r\n                }\r\n\r\n                return cpy;\r\n            }\r\n        </script>\r\n    </body>\r\n</html>","css":"/* html, body {\\n\\twidth: 100%;\\n\\theight: 100%;\\n\\tmargin: 0;\\n\\tpadding: 0;\\n} */","js":"// 请在这里输入代码"}

全部评论

相关推荐

点赞 评论 收藏
分享
迷茫的大四🐶:价格这么低都能满了?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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