$(function() {
    $('#answerQuestion').click(function(e) {
        var lineOrders = $('#lines').sortable('toArray', {attribute: 'lineNum'});

        var ans = [];
        for (var i = 0; i < lineOrders.length; i++) {
            if (lineOrders[i]) {
                ans.push(parseInt(lineOrders[i]));
            }
        }
        console.log();

        $.ajax({
            url: '/question/' + e.target.value,
            type: 'POST',
            data: {'answer': JSON.stringify(ans)},
            success: function(response) {
                $('#result').html(response);
            },
        });
    });

   $('#lines').sortable({containment: "parent"});
   $('#lines').disableSelection();
});

@@ -57,299 +57,8 @@
 ) %7B%0A
-        var lineOrders = $('#lines').sortable('toArray', %7Battribute: 'lineNum'%7D);%0A%0A        var ans = %5B%5D;%0A        for (var i = 0; i %3C lineOrders.length; i++) %7B%0A            if (lineOrders%5Bi%5D) %7B%0A                ans.push(parseInt(lineOrders%5Bi%5D));%0A            %7D%0A        %7D%0A        console.log();%0A%0A
     
@@ -70,16 +70,16 @@
 .ajax(%7B%0A
+
         
@@ -188,19 +188,30 @@
 ringify(
-ans
+getLineOrder()
 )%7D,%0A    
@@ -414,12 +414,295 @@
 tion();%0A
-
 %7D);%0A
+%0Afunction getLineOrder() %7B%0A    var lineOrders = $('#lines').sortable('toArray', %7Battribute: 'lineNum'%7D);%0A    var res = %5B%5D;%0A    for (var i = 0; i %3C lineOrders.length; i++) %7B%0A        if (lineOrders%5Bi%5D) %7B%0A            res.push(parseInt(lineOrders%5Bi%5D));%0A        %7D%0A    %7D%0A    return res;%0A%7D%0A

Refactor get line order functionality into its own function.