def reverse_chain(joints):
    """
    Reverses the hierarchy of the joint chain.

    :param joints: List of joints in the chain to reverse

    :return: the same list of joints in reverse order
    """
    # -- Store the base parent so we can reparent the chain
    # -- back under it
    base_parent = joints[0].getParent()

    # -- Start by clearing all the hierarchy of the chain
    for joint in joints:
        joint.setParent(None)

    # -- Now build up the hierarchy in the reverse order
    for idx in range(len(joints)):
        try:
            joints[idx].setParent(joints[idx + 1])
        except IndexError:
            pass

    # -- Finally we need to set the base parent once
    # -- again
    joints[-1].setParent(base_parent)

    joints.reverse()

    return joints