Refactoring decision tree Currently I have

var l1 = [...];
var l2 = [...]; 
if (l1.length &gt; l2.length){
    var i = l2.indexOf(l1[0]);
    if (i !== -1){
        action_a(i);
    }else{
        action_c();
    }
} else if (l1.length &lt; l2.length){
    var i = l1.indexOf(l2[0]);
    if (i !== -1){
        action_b(i);
    }else{
        action_c();
    }
} else {
    action_c();
}


Which I have could refactor into the following

function foo() {
    var l1 = [...];
    var l2 = [...];
    var i = -1;
    if (l1.length &gt; l2.length){
        i = l2.indexOf(l1[0]);
    } else if (l1.length &lt; l2.length){
        i = l1.indexOf(l2[0]);
    }
    if (i === -1 || l1.length == l2.length) {
        action_c();
        return;
    }
    if (l1.length &gt; l2.length){
        action_a(i);
    } else if (l1.length &lt; l2.length){
        action_b(i);
    }
}


It's a bit better, but I'm checking for the length of the two array twice.  It's also still not as readable as I would like it to be. 

Can you review the above code and offer recommendations on how to do this better?
var l1 = [...];
var l2 = [...]; 
if (l1.length &gt; l2.length){
    actOnDuplicateOfFirstElementIfPresent(l1, l2, action_a);
} else if (l1.length &lt; l2.length){
    actOnDuplicateOfFirstElementIfPresent(l2, l1, action_b);
} else {
    action_c();
}

function actOnDuplicateOfFirstElementIfPresent(la, lb, action) {
    var i = lb.indexOf(la[0]);
    if (i !== -1){
        action(i);
    }else{
        action_c();
    }
}


This Extract Method refactoring eliminates the duplication found in the first two branches.  Eliminating duplication is both an excellent motivation, and an excellent technique, for refactoring.