当前位置:网站首页>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
}
边栏推荐
- NDK does not contain any platforms problem solving
- 点餐系统数据库设计--SQL Server
- 「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader
- Win任务栏图标异常解决
- pytroch、tensorflow对比学习—搭建模型范式(低阶、中阶、高阶API示例)
- matlab simulink 粒子群优化模糊pid控制的电机泵
- 权重等比分配
- Why is the lightweight VsCode used more and more?Why eat my C drive 10G?How to Painlessly Clean VsCode Cache?Teach you how to lose weight for C drive
- Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
- Check控件
猜你喜欢

「游戏引擎 浅入浅出」4.1 Unity Shader和OpenGL Shader

备战金九银十,如何顺利通过互联网大厂Android的笔面试?

WebSocket implements chat function

戴尔PowerEdge服务器R450 RAID配置步骤

How JS works

滚动条样式修改

曲柄滑块机构运动分析和参数优化

pytorch、tensorflow对比学习—张量

pytorch、tensorflow对比学习—计算图和微分机制

Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
随机推荐
What should I do if the neural network cannot be trained?
ApiFile
从离线到实时对客,湖仓一体释放全量数据价值
Windows taskbar icon abnormal solution
Selenium:表单切换
Vsce package after the Command failed: NPM list - production - parseable - the depth = 99999 - loglevel = error exception
2022/07/29 入职健海JustFE团队,我学到了高效开发(年中总结)
Qt Widget 项目对qml的加载实例
Power button (LeetCode) 212. The word search II (2022.07.31)
Robot_Framework:断言
WebSocket implements chat function
移动应用恶意攻击激增500% 三六零天御为APP免费构建安全屏障
Selenium: Popup Handling
湖仓一体电商项目(一):项目背景和架构介绍
uva12326
A,H,K,N
微信小程序获取手机号phonenumber.getPhoneNumber接口开发
ORACLE modify another user package (package)
NDK does not contain any platforms问题解决
crypto-js使用