题解 | #简易深拷贝#

简易深拷贝

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

const _sampleDeepClone = (target) => {
        // 补全代码
        const result = Array.isArray(target) ? [] : {};
        if (typeof target !== "object" || typeof target === "null")
          return target;
        for (const key in target) {
          if (Object.hasOwnProperty.call(target, key)) {
            if (typeof target[key] === "object") {
              result[key] = _sampleDeepClone(target[key]);
            } else {
              result[key] = target[key];
            }
          }
        }
        return result;
      };

全部评论

相关推荐

点赞 评论 收藏
分享
10-11 14:44
济南大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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