Last active
August 29, 2015 14:24
-
-
Save drPytho/f9e3769d5b8e1f8ca6f7 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
/* | |
* Pattern follows | |
* actualKey:'ownKey', <-- The data must contain the key actualKey | |
* actualKey:['ownKey', {/-- pattern --/}] <-- The actualKey must be match a key | |
* <-- to an object in this case. | |
*/ | |
var reformatData = function(data, pattern){ | |
var obj = {}; | |
for (var key in pattern){ | |
if (pattern[key] instanceof Array){ | |
obj[pattern[key][0]] = parseData(data[key], pattern[key][1]); | |
} else { | |
obj[pattern[key]] = data[key]; | |
} | |
} | |
return obj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment