Edit: This is not a duplicate question.  My function is different and doesn't use direct object comparison methods.  I am working through Eloquent Javascript book and in the fourth chapter, the last exercise required a function deepEqual that takes two arguments and compares them.    If the arguments are different types, it should return false. If the arguments are the same type and same value, it should return true otherwise, return false. If the arguments are both objects, their properties and values should be compared. The function call should return true if both objects have same properties and value in the same order. For example, if we have the following objects: object1 = {a: 1, b: 2}, object2 = {a: 1, b: 2}, object3 = {a: 2, b: 1}, comparing object1 and object2 should return true, but comparing object1 and object3 should return false. Lastly, if the objects have nested objects as parameters, a recursive call of deepEqual to compare the nested objects.    So, here is my solution. It is quite convoluted with if/else statements, pardon it.    function deepEqual(obj1, obj2){    var checkForSameTypes = (typeof obj1 === typeof obj2);    if(checkForSameTypes === true){      //same type but not objects     if(typeof obj1 !== "object" &amp;&amp; typeof obj2 !== "object") {       if(obj1 == obj2){         return true;       }else{         return false;       }       // same type and objects     }else if(typeof obj1 === "object" &amp;&amp; typeof obj2 === "object"){        //loop first object and compare properties with 2nd object       for(var prop in obj1){         if(obj2.hasOwnProperty(prop)) {          //if 2nd object has property "prop" compare           if(typeof obj1[prop] === "object" &amp;&amp; typeof obj2[prop] === "object"){             //recursive call             deepEqual(obj1[prop], obj2[prop]);           }else if(obj1[prop] === obj2[prop]) {             //loop goes on to the next property             continue;            }else if(obj1[prop] !== obj2[prop]){             return false;           }          //it doesn't have property "prop" so return false         } else {           return false;         }       }       //finishes loop and all properties are the same       return true;      }    // they are not the same types so return false   } else {     return false;   } }   PROBLEM  The function works fine except when an argument is an object with nested objects.  Take these objects for example   var type = {go: {inside: "yes"}, come: 2}  var see = {go: {inside: "no"}, come: 2}   var fine = {when: 3, go: 4};`   When I compare type and see with a call to deepEqual(type,see);, this returns true which is wrong because the value of the property of the nested object go is different.  I have gone through the entire code on paper, line by line and do not know what I have to do, or if the recursive call isn't working to compare the properties rightly or I just don't have the knowledge yet.   Can anyone offer a solution? or and if possible a better way or thinking process to solve this case?   Note: The code only compares object properties and values. It doesn't need to compare constructors or prototypes.
11800
A strict equality operator will tell you if two object types are equal. However, is there a way to tell if two objects are equal, much like the hash code value in Java?  Stack Overflow question  is similar to this question, but requires a more academic answer. The scenario above demonstrates why it would be necessary to have one, and I'm wondering if there is any equivalent solution.
44701
There are two methods of determining equality in PostGIS.   The equals operator     Obviously these two methods work different, but the docs on ST_Equals are not clear why,     Returns TRUE if the given Geometries are "spatially equal". Use this for a 'better' answer than '='. Note by spatially equal we mean ST_Within(A,B) = true and ST_Within(B,A) = true and also mean ordering of points can be different but represent the same geometry structure. To verify the order of points is consistent, use ST_OrderingEquals (it must be noted ST_OrderingEquals is a little more stringent than simply verifying order of points are the same).   This seems to mean there is two criterion for ST_Equals, and that is that   ST_Within(A,B) = true  ST_Within(B,A) = true   However, that ordering of points does not matter with ST_Equals. Presumably, that would matter with the equal operator then =? But, that doesn't match up with my observation.  So as three in the same questions..   What does the equal operator (=) do? What does the ST_Equals() do? What criteria does spatially equal include that = does not include?
14108
Basically, I'm trying to create an object of unique objects, a set. I had the brilliant idea of just using a JavaScript object with objects for the property names. Such as,  set[obj] = true;   This works, up to a point. It works great with string and numbers, but with other objects, they all seem to "hash" to the same value and access the same property. Is there some kind of way I can generate a unique hash value for an object? How do strings and numbers do it, can I override the same behavior?
113317
I'm trying to assert that one object is "equal" to another object.   The objects are just instances of a class with a bunch of public properties. Is there an easy way to have NUnit assert equality based on the properties?  This is my current solution but I think there may be something better:  Assert.AreEqual(LeftObject.Property1, RightObject.Property1) Assert.AreEqual(LeftObject.Property2, RightObject.Property2) Assert.AreEqual(LeftObject.Property3, RightObject.Property3) ... Assert.AreEqual(LeftObject.PropertyN, RightObject.PropertyN)   What I'm going for would be in the same spirit as the CollectionEquivalentConstraint wherein NUnit verifies that the contents of two collections are identical.
5510
When comparing two strings in c# for equality, what is the difference between InvariantCulture and Ordinal comparison?
330
The primitive types (number, string, etc.) are passed by value, but objects are unknown, because they can be both passed-by-value (in case we consider that a variable holding an object is in fact a reference to the object) and passed-by-reference (when we consider that the variable to the object holds the object itself).  Although it doesn't really matter at the end, I want to know what is the correct way to present the arguments passing conventions. Is there an excerpt from JavaScript specification, which defines what should be the semantics regarding this?
98914
The MSDN documentation on  describes 3 contradicting rules for how the method should work.     If two objects of the same type represent the same value, the hash function must return the same constant value for either object. For the best performance, a hash function must generate a random distribution for all input. The hash function must return exactly the same value regardless of any changes that are made to the object.   Rules 1 &amp; 3 are contradictory to me.  Does Object.GetHashCode() return a unique number based on the value of an object, or the reference to the object. If I override the method I can choose what to use, but I'd like to know what is used internally if anyone knows.
23206
It's a bit difficult to implement a deep object copy function. What steps you take to ensure the original object and the cloned one share no reference?
16134
I have two complex (i.e. objects with string, int, double, List and other home made data type) objects of the same type. I would like to compare the content of both of them to ensure that they are identical. Note: The object doesn't implement .Equals (I have no control on that) and doesn't implement IComparable.   Is there a generic way (reflection?) to compare the content of the two objects?  Thanks!
95768
Is there any way in javascript to create a "weak reference" to another object?   Can anyone think of a way to implement this  behavior in javascript?
42150
I have a set of real numbers $x_1, x_2, \ldots, x_n$ and two functions $f:\mathbb{R} \rightarrow \mathbb{R}$ and $g:\mathbb{R} \rightarrow \mathbb{R}$.  What are the differences between the following statements?   $\forall v \in \{1, \ldots, n\} ~f(x_v) = 0 \vee g(x_v) = 0$ $f(x_v) = 0 \vee g(x_v) = 0 ~\forall v \in \{1, \ldots, n\} ~$
72929
I have a method which is given the parameter "bool sortAscending". Now I want to use LINQ to create sorted list depending on this parameter. I got then this:  var ascendingQuery = from data in dataList                       orderby data.Property ascending                       select data;  var descendingQuery = from data in dataList                       orderby data.Property descending                       select data;   As you can see, both queries differ only in "ascending" resp. "descending". I'd like to merge both queries, but I don't know how. Does anyone have the answer?
57401
I have been working on a Java project for a class for a while now. It is an implementation of a linked list (here called AddressList, containing simple nodes called ListNode). The catch is that everything would have to be done with recursive algorithms. I was able to do everything fine sans one method: public AddressList reverse()      ListNode:    public class ListNode{   public String data;   public ListNode next; }   Right now my reverse function just calls a helper function that takes an argument to allow recursion.  public AddressList reverse(){   return new AddressList(this.reverse(this.head)); }   With my helper function having the signature of private ListNode reverse(ListNode current).  At the moment, I have it working iteratively using a stack, but this is not what the specification requires. I had found an algorithm in C that recursively reversed and converted it to Java code by hand, and it worked, but I had no understanding of it.  Edit: Nevermind, I figured it out in the meantime.  private AddressList reverse(ListNode current, AddressList reversedList){   if(current == null)        return reversedList;   reversedList.addToFront(current.getData());   return this.reverse(current.getNext(), reversedList); }   While I'm here, does anyone see any problems with this route?
108043
I'm seeing some unexpected behaviour with the locker service enabled when updating two fields on an object, one of which is nested inside a sub-object.   I have a lightning application that initialises a JavaScript object and passes references to fields on the object, and the object itself, as attributes to a contained component:  App Markup  &lt;aura:application &gt;     &lt;aura:attribute name="obj" type="object" /&gt;     &lt;aura:handler name="init" value="{!this}" action="{!c.init}" /&gt;      Top level value: &lt;ui:outputText value="{!v.obj.value1}" /&gt; &lt;br/&gt;     Nested value: &lt;ui:outputText value="{!v.obj.sub.value2}" /&gt; &lt;br/&gt;      &lt;c:MultiFieldTest obj="{!v.obj}" value1="{!v.obj.value1}" value2="{!v.obj.sub.value2}" /&gt;      &lt;br/&gt;      &lt;button onclick="{!c.showObj}"&gt;Show Object&lt;/button&gt; &lt;/aura:application&gt;   app controller  ({     init : function(component, event, helper) {         helper.init(component);     },     showObj : function(component, event, helper) {         helper.showObj(component);     } })   app helper:  ({     init : function(cmp) {         var obj={value1:'', sub:{value2:''}};         cmp.set('v.obj', obj);     },     showObj : function(cmp) {         alert('Object = ' + JSON.stringify(cmp.get('v.obj')));     } })   So the concept is there is an object with the structure:  {value1:'',   sub:{      value2:''} }   and I want to pass value1 and sub.value2 as attributes to a component that will update them. However, to ensure that the changes are propagated up and down the food chain (as per : ) I am also passing in the object itself. Essentially I want the contained component to update a couple of fields and propagate the changes without having to know which fields it is updating.  The containing component markup:  &lt;aura:component&gt;     &lt;aura:attribute name="value1" type="String" /&gt;     &lt;aura:attribute name="value2" type="String" /&gt;     &lt;aura:attribute name="obj" type="object"/&gt;      &lt;button onclick="{!c.setValues}"&gt;Set Values&lt;/button&gt;  &lt;/aura:component&gt;   controller:  ({     setValues : function(component, event, helper) {         helper.setValues(component);     } })   helper:  ({     setValues : function(cmp) {         var obj=cmp.get('v.obj');         console.log('Obj before = ' + JSON.stringify(obj));          cmp.set('v.value1', 'Value 1');         cmp.set('v.value2', 'Value 2');           obj=cmp.get('v.obj');         console.log('Obj after = ' + JSON.stringify(obj));          cmp.set('v.obj', obj);     } })   So when the user clicks the button, strings are set into the value1/value2 attributes and the underlying object 'reset' into the page. I then click on the 'Show Object' button, and the results are as expected with the locker service deactivated.   However, when I activate the locker service, only the second update 'sticks' and obj.value1 is empty, although both ui:outputText elements show the value1/value2 details as expected. What appears to be happening is that setting the first attribute updates the page as expected, and the object, but setting the second attribute updates the page and an earlier version of the object, minus the value1 details.  However, if I don't get the obj attribute at the beginning of the setValues method, it works:  setValues : function(cmp) {     // var obj=cmp.get('v.obj'); &lt;---- removed this      cmp.set('v.value1', 'Value 1');     cmp.set('v.value2', 'Value 2');       var obj=cmp.get('v.obj');     console.log('Obj after = ' + JSON.stringify(obj));      cmp.set('v.obj', obj); }   So pretty easy to work around, but I'm curious as to why this would be necessary with the locker service enabled - there's no secure versions of anything in play and the attributes are all accessible to the component. Its almost like the act of looking at the object fixes a version somewhere, and all updates retrieve that version before applying their update, rather than retrieving the latest version.
29326
Here is my test code and picture:  import bpy   # Simple property reading/writing from ID properties. # This is what the RNA would do internally. def get_float(self):     return self["testprop"]   def set_float(self, value):     self["testprop"] = value  #bpy.types.Scene.test_float = bpy.props.FloatProperty(get=get_float,set=set_float) bpy.types.Scene.test_float = bpy.props.FloatProperty()   bpy.context.scene.test_float = 12.34     When I don't explicitly set the "get/set" function for my property, after assigning the value, I can get the property value by 'scene["test_float"]', but if I explicitly set the "get/set" function, then if I try to type in the same commands, I will receive a error "KeyError: 'bpy_struct[key]: key "test_float" not found'" . So what should I do to get the same results by using explicitly  "get/set" function?
24474
What is the best way to find if an object is in an array?  This is the best way I know:    function include(arr, obj) {   for (var i = 0; i &lt; arr.length; i++) {     if (arr[i] == obj) return true;   } }  console.log(include([1, 2, 3, 4], 3)); // true console.log(include([1, 2, 3, 4], 6)); // undefined
118496
I want to sort a list of objects of a class by 2 ways. I am able to do custom sort by overwriting the compareTo method.  But I have two lists and I want to sort them differently.  Can I still accomplish this by calling the list.sort() method?  global class myClass implements Comparable{      public integer Total{get;set;}     public integer numOfDays{get;set;}      global Integer compareTo(Object compareTo) {         myClass compareToEmp = (myClass)compareTo;         if (Total == myClass.Total) return 0;         if (Total &gt; myClass.Total) return 1;         return -1;             } }   In the above example, how can I also be able to sort by "numOfDays"?  //UPDATE:  I actually wanted to sort list by single property.   But use different properties to sort different lists.  I ended up adding a new field to my class for sorting purpose.  global class myClass implements Comparable{      public integer Total{get;set;}     public integer numOfDays{get;set;}     public boolean isA {get;set;}      global Integer compareTo(Object compareTo) {         myClass compareToEmp = (myClass)compareTo;         if(isA){          if (Total == myClass.Total) return 0;         if (Total &gt; myClass.Total) return 1;             return -1; }         else{              if (Total == myClass.numOfDays) return 0;         if (Total &gt; myClass.numOfDays) return 1;             return -1;          }            } }