old_contents: $(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();
  });
  
new_contents: $(function() {
      $('#answerQuestion').click(function(e) {
          $.ajax({
              url: '/question/' + e.target.value,
              type: 'POST',
              data: {'answer': JSON.stringify(getLineOrder())},
              success: function(response) {
                  $('#result').html(response);
              },
          });
      });
  
     $('#lines').sortable({containment: "parent"});
     $('#lines').disableSelection();
  });
  
  function getLineOrder() {
      var lineOrders = $('#lines').sortable('toArray', {attribute: 'lineNum'});
      var res = [];
      for (var i = 0; i < lineOrders.length; i++) {
          if (lineOrders[i]) {
              res.push(parseInt(lineOrders[i]));
          }
      }
      return res;
  }
  
subject: Refactor get line order functionality into its own function.