I have a chunk of code that's working properly but it's way too complicated to read:addCollision (bodyA, bodyB) {    var bodyC, i3;    if (bodyA.collision === null && bodyB.collision === null) {        bodyA.collision = this.collisions.length;        bodyB.collision = bodyA.collision;        this.collisions.push([bodyA, bodyB]);    } else if (bodyA.collision !== null && bodyB.collision === null) {        bodyB.collision = bodyA.collision;        this.collisions[bodyA.collision].push(bodyB);    } else if (bodyB.collision !== null && bodyA.collision === null) {        bodyA.collision = bodyB.collision;        this.collisions[bodyB.collision].push(bodyA);    } else if (bodyA.collision !== bodyB.collision) {        var bodyBCollisionIndex = bodyB.collision;        for (i3 = 0; i3 < this.collisions[bodyB.collision].length; ++i3){            bodyC = this.collisions[bodyBCollisionIndex][i3];            if (bodyC !== bodyB) {                bodyC.collision = bodyA.collision;                this.collisions[bodyA.collision].push(bodyC);            }        }        this.collisions[bodyB.collision].length = 0;    }}Basically, it's called when two bodies collide. It's main purpose is to create a new array containing the two bodies that just collided and add it to another array containing all the collisions in that frame.Actually, it does a little more too: If one of the two bodies was already colliding with a third body before, the code will not create a new array for the collision, but instead add the new colliding body to the already existing collision array. If both bodies were already colliding with other bodies, then it should merge the collision arrays without letting any duplicates.How can I make this code more clear?
Collision manager
javascript;collision
If statements respond to truthy valuesI am not a javascript expert (so I apologize if i've messed up the syntax somewhere), but in javascript the 'if' statement responds to truthy values:i.e.    if (examStarted)    {        GetOutOfBedFAST();    }you don't need to write:    if (examStarted == true ) etchide details behind methods so it's easy to readaddCollision (bodyA, bodyB) {    var bodyC, i3;    if (    noCollision(bodyA, bodyB))     {        coolName1(bodyA, bodyB)    }     else if (ACollidesNotB(bodyA, bodyB) )     {        coolName2(bodyA, bodyB)    }     // etc etc}noCollision(bodyA, bodyB){    return (bodyA.collision === null && bodyB.collision === null);}coolName1(bodyA, bodyB){        bodyA.collision = this.collisions.length;        bodyB.collision = bodyA.collision;        this.collisions.push([bodyA, bodyB]);}ACollidesNotB(bodyA, bodyB){    return (bodyA.collision !== null && bodyB.collision === null);}coolName2(bodyA, bodyB){       bodyB.collision = bodyA.collision;        this.collisions[bodyA.collision].push(bodyB);}missing abstractions?You don't really want to be writing code like this: if then do this, else if then do that, elseif then do another. This type of code should be avoided.What you want to be writing, in this type of sitation is things like this:```Body b1 = Factory.ReturnBody();b1.RespondToCollision();```Something like that. Use objects to send messages to each other. That way your code will be more OOP and easier to change when the time comes.