code: function encode(position_array){
  
    if(!_.isArray(position_array) || position_array.length<=0){
      throw new Error('Array of tree positions required');
    } 
    
    var left_position_array = _.map(position_array, function(v){return v;});
    var right_position_array = _.map(position_array, function(v){return v;});
  
    // lets modify the last position in the right hand sequence so it is one more than the left
    var last_position = right_position_array.pop();
    
    last_position++;
  
    right_position_array.push(last_position);
  
    return {
      left:calculate_encoding_from_tree_position(left_position_array),
      right:calculate_encoding_from_tree_position(right_position_array)
    }
  }
docs: Uses calculate_encoding_from_tree_position to calculate the left and right encoding for a given node It simply adds 1 to the last position in the array to get the encodings for its next sibling