Skip to content

Instantly share code, notes, and snippets.

@longsangstan
Created December 15, 2015 10:21
Show Gist options
  • Save longsangstan/2b2c5d5578112a9301b4 to your computer and use it in GitHub Desktop.
Save longsangstan/2b2c5d5578112a9301b4 to your computer and use it in GitHub Desktop.
test
/**
* Transform a to another format
* @param {object} a - Sample data
* @return {object} Returns transformed a
*/
function transform(a) {
var new_a = {};
(function find_msg(item, str) {
for (var key in item) {
if (key === 'message') new_a[str] = item[key];
else if (str === '') find_msg(item[key], key);
else if (str === 'items') find_msg(item[key], str + '[' + key + ']');
else find_msg(item[key], str + '.' + key);
}
})(a, '');
return new_a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment