Skip to content

Instantly share code, notes, and snippets.

@drPytho
Last active August 29, 2015 14:24
Show Gist options
  • Save drPytho/f9e3769d5b8e1f8ca6f7 to your computer and use it in GitHub Desktop.
Save drPytho/f9e3769d5b8e1f8ca6f7 to your computer and use it in GitHub Desktop.
/*
* 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