当前位置:网站首页>Compare two objects are the same depth
Compare two objects are the same depth
2022-08-01 05:34:00 【not enough time later】
/** * Deeply compares whether two objects are the same * @param {Object} oldData * @param {Object} newData */
export const equals2Obj = (oldData, newData) => {
// When the type is a primitive type,如果相同,则返回true
if (oldData === newData) return true
if (isObject(oldData) && isObject(newData) && Object.keys(oldData).length === Object.keys(newData).length) {
// The type is object and the number of elements is the same
// Iterate over all properties in all objects,判断元素是否相同
for (const key in oldData) {
if (Object.prototype.hasOwnProperty.call(oldData, key)) {
if (!equals2Obj(oldData[key], newData[key])) {
// Objects have different properties 返回false
return false
}
}
}
} else if (isArray(oldData) && isArray(newData) && oldData.length === newData.length) {
// The type is an array and the arrays have the same length
for (let i = 0, length = oldData.length; i < length; i++) {
if (!equals2Obj(oldData[i], newData[i])) {
// If the array elements have different elements,返回false
return false
}
}
} else {
// 其它类型,均返回false
return false
}
// 走到这里,Indicates that all elements in an array or object are the same,返回true
return true
}
边栏推荐
- Challenge 52 days to memorize Peppa Pig (Day 01)
- AspNet.WebApi.Owin 自定义Token请求参数
- 将CSV文件快速导入MySQL中
- WebSocket实现聊天功能
- Qt Widget project loading example of qml
- pytroch、tensorflow对比学习—专栏介绍
- Robot_Framework:常用内置关键字
- 微信小程序获取手机号phonenumber.getPhoneNumber接口开发
- LeetCode 0149. 直线上最多的点数
- Seleniu: Common operations on elements
猜你喜欢

PaddleX部署推理模型和GUI界面测试结果不一致的解决方法

基于MATLAB的BP神经网络进行语音特征信号分类

Dialogue with the father of MySQL: One excellent programmer is worth 5 ordinary programmers

pytroch、tensorflow对比学习—搭建模型范式(低阶、中阶、高阶API示例)

类神经网络训练不起来怎么办

Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)

从离线到实时对客,湖仓一体释放全量数据价值

Qt Widget 项目对qml的加载实例

Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)

Windows taskbar icon abnormal solution
随机推荐
用控件当画笔获得bitmap代码记录
可持久化线段树
[MySQL] 多表查询
Selenium: Popup Handling
Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
轻量级的VsCode为何越用越大?为什么吃了我C盘10G?如何无痛清理VsCode缓存?手把手教你为C盘瘦身
leetcode43 字符串相乘
Selenium: mouse, keyboard events
After the image is updated, Glide loading is still the original image problem
请求/响应拦截器写法
图片更新之后Glide加载依旧是原来的图片问题
数据湖:数据同步工具NiFi
mysql的行锁和间隙锁
Jupyter shortcuts
WPF入门项目必知必会-初步了解数据绑定 binding
华为Android开发面试后得出的面试秘诀
2022.7.26 模拟赛
Robot_Framework: commonly used built-in keywords
权重等比分配
Qt Widget project loading example of qml