deepequals

JS function “Deep comparison”. Object comparison

一笑奈何 提交于 2019-12-31 05:59:45
问题 I wanted to implement JS function "Deep comparison" and encounter on one interesting feature. 1st case - var arrValuesObjA = [{ is: "an" }, 2]; var arrValuesObjB = [{ is: "an" }, 2]; console.log(Array.isArray(arrValuesObjA), arrValuesObjA); //true Array [ {…}, 2 ] // 0: Object { is: "an" } 1: 2 length: 2 console.log(Array.isArray(arrValuesObjB), arrValuesObjB); // true Array [ {…}, 2 ] // 0: Object { is: "an" } 1: 2 length: 2 for (let i = 0; i < arrValuesObjA.length; i++) { console.log

Function checking for “deep equality” of nested objects

陌路散爱 提交于 2019-12-13 02:38:21
问题 I am trying to write a function that checks if two objects have the same values. This function requires that I check for the equality of any objects that are stored as values inside the original objects. The approach I have developed (see code below) is to first check the equality of non-object values. Then, if these all match, I iterate over the objects again and make a recursive call to the original function, which allows me to compare each nested level of the two objects. However, this

On Java 7's equals() and deepEquals()

本秂侑毒 提交于 2019-12-05 13:05:23
问题 Method description says: Returns true if the arguments are deeply equal to each other and false otherwise... Equality is determined by using the equals method of the first argument. Which (to me) suggests that Objects are deeply equal if every object they maintain references to are also equal using the equals() method. And every objects they have a reference to are also equal. And .. So .. equality is determined by using the equals method of the first argument. How is this different from

JS function “Deep comparison”. Object comparison

隐身守侯 提交于 2019-12-02 12:21:05
I wanted to implement JS function "Deep comparison" and encounter on one interesting feature. 1st case - var arrValuesObjA = [{ is: "an" }, 2]; var arrValuesObjB = [{ is: "an" }, 2]; console.log(Array.isArray(arrValuesObjA), arrValuesObjA); //true Array [ {…}, 2 ] // 0: Object { is: "an" } 1: 2 length: 2 console.log(Array.isArray(arrValuesObjB), arrValuesObjB); // true Array [ {…}, 2 ] // 0: Object { is: "an" } 1: 2 length: 2 for (let i = 0; i < arrValuesObjA.length; i++) { console.log(arrValuesObjA[i] === arrValuesObjB[i]); // First iteration - false, second iteration - true. // Means Object