Created
November 12, 2014 12:47
-
-
Save slaykovsky/27ec15fcb59163ceeaf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var transformAsync = function(objects, map, data) { | |
console.log('-----------------------------------'); | |
console.log('Function transformAsync is started.'); | |
var keys = Object.keys(map); | |
async.each(objects, function(object, done) { | |
console.log('------------------------------------------------------------'); | |
console.log('Processing object: %s', util.inspect(object, { depth: null })); | |
console.log('------------------------------------------------------------'); | |
async.each(keys, function(key) { | |
if(typeof map[key] === 'object') { | |
var nestedKeys = Object.keys(map[key]); | |
async.each(nestedKeys, function(nestedKey) { | |
var nestedValue = map[key][nestedKey]; | |
if(nestedValue === object.key) { | |
console.log('Nested value is %s:', nestedValue); | |
console.log('This value (%s) has been changed to %s:', nestedValue, object.val); | |
map[key][nestedKey] = object.val; | |
} | |
}); | |
} else { | |
var value = map[key]; | |
if(value === object.key) { | |
console.log('Value is %s:', value); | |
console.log('This value (%s) has been changed to %s:', value, object.val); | |
map[key] = object.val; | |
} | |
} | |
}); | |
}); | |
console.log('Function async is ended.'); | |
console.log('--------------------------------------'); | |
data(null, map); | |
}; | |
transformAsync(dataObject, mapObject, function(err, data) { | |
console.log('Wellcome to transformAsync callback!'); | |
console.log(util.inspect(data, { depth: null })); | |
console.log('SUCCESS!'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment