function degree(graph, kind) {
  var getNodeDegree,
    sortedDegrees = [],
    result = Object.create(null),
    nodeDegree;

  kind = (kind || 'both').toLowerCase();
  if (kind === 'both' || kind === 'inout') {
    getNodeDegree = inoutDegreeCalculator;
  } else if (kind === 'in') {
    getNodeDegree = inDegreeCalculator;
  } else if (kind === 'out') {
    getNodeDegree = outDegreeCalculator;
  } else {
    throw new Error('Expected centrality degree kind is: in, out or both');
  }

  graph.forEachNode(calculateNodeDegree);

  return result;

  function calculateNodeDegree(node) {
    var links = graph.getLinks(node.id);
    result[node.id] = getNodeDegree(links, node.id);
  }
}
Calculates graph nodes degree centrality (in/out or both).

@see http://en.wikipedia.org/wiki/Centrality#Degree_centrality

@param {ngraph.graph} graph object for which we are calculating centrality.
@param {string} [kind=both] What kind of degree centrality needs to be calculated:
  'in'    - calculate in-degree centrality
  'out'   - calculate out-degree centrality
  'inout' - (default) generic degree centrality is calculated