当前位置:网站首页>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
}
边栏推荐
- 从离线到实时对客,湖仓一体释放全量数据价值
- Selenium: Element wait
- Selenium:下拉框操作
- Selenium: JS operation
- 2022.7.26 模拟赛
- 微信小程序获取手机号phonenumber.getPhoneNumber接口开发
- pytroch、tensorflow对比学习—功能组件(数据管道、回调函数、特征列处理)
- ModuleNotFoundError: No module named 'tensorflow.keras' error message solution
- 导致锁表的原因及解决方法
- ORACLE modify another user package (package)
猜你喜欢
【MySQL必知必会】 表的优化 | 充分利用系统资源
Malicious attacks on mobile applications surge by 500%
基于MATLAB的BP神经网络进行语音特征信号分类
pytorch、tensorflow对比学习—张量
备战金九银十,如何顺利通过互联网大厂Android的笔面试?
pytroch、tensorflow对比学习—专栏介绍
Windows taskbar icon abnormal solution
Selenium:弹窗处理
The solution to the inconsistency between the PaddleX deployment inference model and the GUI interface test results
Flip letters using string container
随机推荐
Selenium: mouse, keyboard events
ORACLE modify another user package (package)
零序电流继电器器JL-8C-12-2-2
pytroch、tensorflow对比学习—搭建模型范式(构建模型方法、训练模型范式)
The sword refers to Offer 68 - I. Nearest Common Ancestor of Binary Search Trees
Robot_Framework: commonly used built-in keywords
Speed up your programs with bitwise operations
matplotlib pyplot
matlab 风速模型 小波滤波
中国的机器人增长
用位运算为你的程序加速
小白的0基础教程SQL: 关系数据库概述 02
AspNet.WebApi.Owin custom Token request parameters
leetcode43 string multiplication
Selenium: upload and download files
LeetCode 0150. 逆波兰表达式求值
Malicious attacks on mobile applications surge by 500%
Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
AspNet.WebApi.Owin 自定义Token请求参数
pytroch、tensorflow对比学习—使用GPU训练模型