当前位置:网站首页>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:浏览器操作
- Selenium:元素等待
- Robot_Framework:常用内置关键字
- pytroch、tensorflow对比学习—搭建模型范式(构建模型方法、训练模型范式)
- The solution to the inconsistency between the PaddleX deployment inference model and the GUI interface test results
- The sword refers to Offer 68 - I. Nearest Common Ancestor of Binary Search Trees
- I met a shell script
- SL-12/2过流继电器
- weight distribution
- 用控件当画笔获得bitmap代码记录
猜你喜欢
随机推荐
Selenium: element positioning
Causes and solutions of lock table
pytroch、tensorflow对比学习—使用GPU训练模型
vim configuration + ctag is as easy to read code as source insight
ApiFile
SL-12/2过流继电器
混合型界面:对话式UI的未来
About making a progress bar for software initialization for Qt
pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)
小白的0基础教程SQL: 什么是SQL 01
说说js中使用for in遍历数组存在的bug
滚动条样式修改
【MySQL必知必会】 表的优化 | 充分利用系统资源
uva12326
第5章——以程序方式处理MySQL数据表的数据
Power button (LeetCode) 212. The word search II (2022.07.31)
Seleniu: Common operations on elements
HJS-DE1/2时间继电器
【FiddlerScript】利用FiddlerScript抓包保利威下载
Speed up your programs with bitwise operations