Created
December 15, 2015 10:21
-
-
Save longsangstan/2b2c5d5578112a9301b4 to your computer and use it in GitHub Desktop.
test
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
/** | |
* 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