Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function deepEqual(first, second) {
- if (first === undefined && second === undefined)
- return true;
- if ([first, second].filter(item => item === undefined).length === 1)
- return false;
- let [firstType, secondType] = [typeof first, typeof second];
- if (firstType !== "object" && secondType !== "object")
- return first === second;
- let firstProps = first === null ? [] : Object.getOwnPropertyNames(first).sort();
- let secondProps = second === null ? [] : Object.getOwnPropertyNames(second).sort();
- if (firstProps.length !== secondProps.length)
- return false;
- for (i in firstProps)
- if (firstProps[i] !== secondProps[i])
- return false;
- for (i in firstProps) {
- let currentFirstProp = firstProps[i];
- if (!secondProps.includes(currentFirstProp) || !deepEqual(first[currentFirstProp], second[currentFirstProp]))
- return false;
- }
- return true;
- }
- function main() {
- let a = { location: [1, 1, 1], rotation: [0, 0, 0] }
- let b = { location: [1, 1, 1], rotation: [0, 0, 0] }
- console.log(deepEqual(null, a));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement