Created
January 16, 2016 22:16
-
-
Save wgottschalk/284d88c4b5ad5ae1d3fa 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
function buildObject(str) { | |
var newObj = {}; | |
var newKey, newVal; | |
var elstart = 1; | |
var elend = 1; | |
var contentsStr = str.substring(1,str.length-1); | |
contentsStr = contentsStr.trim(); | |
var contentsLength = contentsStr.length; | |
if (contentsLength === 0) { | |
console.log('broke out'); | |
return newObj; | |
} | |
for (var i = 0; i < str.length; i++) { | |
if (str[i] === ':') { | |
elend = i; | |
if (elend - elstart > 0) { | |
newKey = str.substring(elstart,elend).trim(); | |
newKey = returnTerminalDatatype(newKey); | |
} | |
elstart = i+1; | |
} | |
if (str[i] === '}' || str[i] === ',') { | |
elend = i; | |
if (elend - elstart > 0) { | |
newVal = str.substring(elstart,elend).trim(); | |
newVal = parseTo(newVal); | |
} | |
elstart = i+1; | |
} | |
newObj[newKey] = newVal; | |
} | |
return newObj; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment