gravity.js
function reduce(map, path) {
		var mapNode, prefix, split, splits = getResourcePathSplits(path),
			subValue, suffix;
		while (splits.length) {
			split = splits.shift();
			suffix = split[1];
			prefix = suffix ? split[0] + '/' : split[0];
			mapNode = map[prefix];
			if (mapNode) {
				if (!suffix || typeof mapNode === 'string') {
					return { map: mapNode, prefix: prefix, suffix: suffix };
				}
				if (typeof mapNode === 'object') {
					subValue = reduce(mapNode, suffix);
					if (subValue) {
						subValue.prefix = prefix + '/' + subValue.prefix;
						return subValue;
					}
				}
			}
		}
		return { map: map, prefix: '', suffix: path };
	}
function reduce(map, path) {
		var mapNode, prefix, split, splits = getResourcePathSplits(path),
			subValue, suffix;
		while (splits.length) {
			split = splits.shift();
			suffix = split[1];
			prefix = suffix ? split[0] + '/' : split[0];
			mapNode = map[prefix];
			if (mapNode) {
				if (!suffix || typeof mapNode === 'string') {
					return { map: mapNode, prefix: prefix, suffix: suffix };
				}
				if (typeof mapNode === 'object') {
					subValue = reduce(mapNode, suffix);
					if (subValue) {
						subValue.prefix = prefix + '/' + subValue.prefix;
						return subValue;
					}
				}
			}
		}
		return { map: map, prefix: '', suffix: path };
	}
function reduce ( map , path ) { var mapNode , prefix , split , splits = getResourcePathSplits ( path ) , subValue , suffix ; while ( splits . length ) { split = splits . shift ( ) ; suffix = split [ 1 ] ; prefix = suffix ? split [ 0 ] + '/' : split [ 0 ] ; mapNode = map [ prefix ] ; if ( mapNode ) { if ( ! suffix || typeof mapNode === 'string' ) { return { map : mapNode , prefix : prefix , suffix : suffix } ; } if ( typeof mapNode === 'object' ) { subValue = reduce ( mapNode , suffix ) ; if ( subValue ) { subValue . prefix = prefix + '/' + subValue . prefix ; return subValue ; } } } } return { map : map , prefix : '' , suffix : path } ; }
Given a map and a resource path, drill down in the map to find the most specific map node that matches the path.  Return the map node, the matched path prefix, and the unmatched path suffix.
Given a map and a resource path drill down in the map to find the most specific map node that matches the path . Return the map node the matched path prefix and the unmatched path suffix .