lib/json-dry.js
function walk(obj, fnc, result) {

	var is_root,
	    keys,
	    key,
	    ret,
	    i;

	if (!result) {
		is_root = true;

		if (Array.isArray(obj)) {
			result = [];
		} else {
			result = {};
		}
	}

	keys = Object.keys(obj);

	for (i = 0; i < keys.length; i++) {
		key = keys[i];

		if (typeof obj[key] == 'object' && obj[key] != null) {
			if (Array.isArray(obj[key])) {
				result[key] = walk(obj[key], fnc, []);
			} else {
				result[key] = walk(obj[key], fnc, {});
			}
			result[key] = fnc(key, result[key], result);
		} else {
			// Fire the function
			result[key] = fnc(key, obj[key], obj);
		}
	}

	if (is_root) {
		result = fnc('', result);
	}

	return result;
}
function walk(obj, fnc, result) {

	var is_root,
	    keys,
	    key,
	    ret,
	    i;

	if (!result) {
		is_root = true;

		if (Array.isArray(obj)) {
			result = [];
		} else {
			result = {};
		}
	}

	keys = Object.keys(obj);

	for (i = 0; i < keys.length; i++) {
		key = keys[i];

		if (typeof obj[key] == 'object' && obj[key] != null) {
			if (Array.isArray(obj[key])) {
				result[key] = walk(obj[key], fnc, []);
			} else {
				result[key] = walk(obj[key], fnc, {});
			}
			result[key] = fnc(key, result[key], result);
		} else {
			// Fire the function
			result[key] = fnc(key, obj[key], obj);
		}
	}

	if (is_root) {
		result = fnc('', result);
	}

	return result;
}
function walk ( obj , fnc , result ) { var is_root , keys , key , ret , i ; if ( ! result ) { is_root = true ; if ( Array . isArray ( obj ) ) { result = [ ] ; } else { result = { } ; } } keys = Object . keys ( obj ) ; for ( i = 0 ; i < keys . length ; i ++ ) { key = keys [ i ] ; if ( typeof obj [ key ] == 'object' && obj [ key ] != null ) { if ( Array . isArray ( obj [ key ] ) ) { result [ key ] = walk ( obj [ key ] , fnc , [ ] ) ; } else { result [ key ] = walk ( obj [ key ] , fnc , { } ) ; } result [ key ] = fnc ( key , result [ key ] , result ) ; } else { // Fire the function result [ key ] = fnc ( key , obj [ key ] , obj ) ; } } if ( is_root ) { result = fnc ( '' , result ) ; } return result ; }
Map an object

@author   Jelle De Loecker   <jelle@develry.be>
@since    0.4.2
@version  1.0.0

@param    {Object}     obj     The object to walk over
@param    {Function}   fnc     The function to perform on every entry
@param    {Object}     result  The object to add to

@return   {Object}
Map an object