/**
 * Created by Kanthanarasimhaiah on 14/11/13.
 */
fs = require('fs');

var num_of_tasks;
var total_time;
var fileName = process.argv[2];

fs.readFile(fileName, 'utf8', function (err,data) {
    if (err) {
        return console.log(err);
    }
    //console.log(data);

    var input=data.split('\n');
    var line1 = input[0].split(' ');
    num_of_tasks=parseInt(line1[0], 10);
    total_time=parseInt(line1[1], 10);
    console.log("Numer of Tasks:", num_of_tasks);
    console.log("Total Time:", total_time);

    // read in the tasks
    var queue= [];

    for(var j=1;j<num_of_tasks;j++) {
        var task_data=input[j].split(' ');
        var task = {id         :          task_data[0],
                    start_time : parseInt(task_data[1], 10),
                    duration   : parseInt(task_data[2], 10)};
        queue.push(task);
    }
    function sort_function (a, b) {
        return a.start_time - b.start_time;
    }
    queue.sort(sort_function);
    console.log("Tasks:");
    console.log(queue);
});


@@ -72,75 +72,51 @@
 );%0A%0A
-var num_of_tasks;%0Avar total_time;%0Avar fileName = process.argv%5B2%5D;%0A%0A
+function readTasks (file) %7B%0A    var data = 
 fs.r
@@ -126,25 +126,25 @@
 File
+Sync
 (file
-Name
 , 'utf8'
 , fu
@@ -143,108 +143,8 @@
 tf8'
-, function (err,data) %7B%0A    if (err) %7B%0A        return console.log(err);%0A    %7D%0A    //console.log(data
 );%0A%0A
@@ -216,16 +216,20 @@
 ');%0A    
+var 
 num_of_t
@@ -261,16 +261,20 @@
 0);%0A    
+var 
 total_ti
@@ -303,102 +303,8 @@
 10);
-%0A    console.log(%22Numer of Tasks:%22, num_of_tasks);%0A    console.log(%22Total Time:%22, total_time);
 %0A%0A  
@@ -634,24 +634,25 @@
 ask);%0A    %7D%0A
+%0A
     function
@@ -764,35 +764,283 @@
     
-console.log(%22Tasks:%22);%0A    
+return %7Bnum_of_tasks: num_of_tasks,%0A            total_time:   total_time,%0A            task_queue:   queue%7D;%0A%7D%0A%0Avar fileName = process.argv%5B2%5D;%0Avar tasks = readTasks(fileName);%0A%0Aconsole.log(%22Numer of Tasks:%22, tasks.num_of_tasks);%0Aconsole.log(%22Total Time:%22, tasks.total_time);%0A
 cons
@@ -1051,17 +1051,52 @@
 log(
-q
+%22Task Q
 ueue
+:%22
 );%0A
-%7D
+console.log(tasks.task_queue
 );%0A%0A

Move task reading into a standalone function.