code: function index(intervals) {
  	var sorted = intervals.slice(0).sort((a, b) => cmp(a.start, b.start));
  	return findEnd(toTree(sorted, 0, sorted.length));
  }
docs: Build index. intervals :: [{start, end, ...}, ...]