Last active
October 12, 2016 14:12
-
-
Save theaccordance/47e7a48ff40c36449ae671518a226c07 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| var source = { | |
| "alpha": "string alpha", | |
| "bravo": { | |
| "charlie": "string bravo.charlie", | |
| "delta": "string bravo.delta", | |
| "echo": { | |
| "foxtrot": 'string bravo.echo.foxtrot', | |
| "gamma": 'string bravo.echo.gamma', | |
| "hotel": "string bravo.echo.hotel" | |
| } | |
| } | |
| }, | |
| dictionary = {}, | |
| pointer = 'a'; | |
| function nextChar(a) { | |
| return String.fromCharCode(a.charCodeAt() + 1); | |
| } | |
| function getPointer(string) { | |
| pointer = nextChar(pointer); | |
| dictionary[pointer] = string; | |
| return ['@', pointer].join(':'); | |
| } | |
| function minifyKeys(obj) { | |
| var key, | |
| has = Object.prototype.hasOwnProperty.bind(obj); | |
| for (key in obj) { | |
| if (has(key)) { | |
| switch (typeof obj[key]) { | |
| case 'object': | |
| minifyKeys(obj[key]); | |
| break; | |
| case 'string': | |
| obj[key] = getPointer(obj[key]); | |
| } | |
| } | |
| } | |
| } | |
| minifyKeys(source); | |
| setTimeout(function () { | |
| console.log(source); | |
| console.log(dictionary); | |
| }, 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment