Skip to content

Instantly share code, notes, and snippets.

@slaykovsky
Created November 12, 2014 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save slaykovsky/27ec15fcb59163ceeaf3 to your computer and use it in GitHub Desktop.
Save slaykovsky/27ec15fcb59163ceeaf3 to your computer and use it in GitHub Desktop.
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