File size: 639 Bytes
0936134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var fs = require('fs');

exports.getRepertoire = getRepertoire;

//Get the events from the given file.  If the file does not exist, or is unparseable, return an error. 
function getRepertoire (filename, repertoireCallback) {
  var repertoire = [];
  fs.readFile(filename, function (err, data) {
    if(!err) {
      repertoire = JSON.parse(data);
      repertoire.sort(compareTitles);
      repertoireCallback(repertoire, err);
    } else {
      repertoireCallback(repertoire, err);
    }
  });
}

function compareTitles(rep1,rep2) {
  if (rep1.title < rep2.title)
    return -1;
  if (rep1.title > rep2.title)
    return 1;
  return 0;
}