Find out if two children/gameObjects have the same parent.

I am trying to find out if two or more gameObjects within a list have the same parent by comparing them.

Example :

 if(child1.transform.parent == child2.transform.parent)
 {
  /////do this
 }

   or

 childList : List.<Transform> = new List.<Transform>();
 currentObject : Transform; ///the current gameObject


 if(childList*.transform.parent ==    gameObject.transform.parent)//////the children in childList and the currentObject have the same parent*

{
//////do thisenter code here
}
Any help is greatly appreciated.

Here’s some sample code to help push you in the right direction.

bool ShareSameParent (IEnumerable<Transform> childList)
{
  foreach (var child1 in childList)
  {
    foreach (var child2 in childList)
    {
      if (child1 == child2)
        continue;
      if (child1.parent == child2.parent)
        return true;
    }
  }

  return false;
}

I haven’t tested this code, and it’s written in C#, but it should be very simple to convert to JavaScript.

Thanks for the reply but I have already tested something similar by comparing child1.parent to child2.parent or child.parent to gameObject.parent but it never lets me pass to the next line.
If I say :

if(childList*.transform.parent == gameObject.transform.parent)*

{
print(“a”);
}
//considering that the children in the childList and the gameObject have the same parent
It wont print the line