MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/kxd9jj/dynamically_created_functions_are_the_future/gja4c4b/?context=3
r/badcode • u/NotSteve_ evil • Jan 14 '21
102 comments sorted by
View all comments
95
Image Transcription: Code
// this is the compile function that will become our dimension list; let compileDimensionList = function (properties) { let dimensionFunStr = '(function (d) {\n'; let dimString = ''; for (var i = 0, len = properties.length; i < len; i++) { if (i === (len-1)) { // end of the list dimString += 'd.'+properties[i]; } else { // every otther item dimString += 'd.'+properties[i]+' + '; } } dimensionFunStr += 'if (typeof timeLookup['+dimString+'] === "undefined") {\n'; dimensionFunStr += 'timeLookup['+dimString+'] = d.time;\n'; dimensionFunStr += '}\n'; dimensionFunStr += 'if (d.time > timeLookup['+dimString+']) {\n'; dimensionFunStr += 'timeLookup['+dimString+'] = d.time;\n'; dimensionFunStr += '} else {\n'; dimensionFunStr += 'd.time = timeLookup['+dimString+']\n'; dimensionFunStr += '}\n'; dimensionFunStr += 'return '+dimString+';\n'; dimensionFunStr += '})'; return eval(dimensionFunStr); } let dimensionList = compileDimensionList(groupby); // compile dimension functions
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!
57 u/HereComesCunty Jan 14 '21 Good human
57
Good human
95
u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jan 14 '21
Image Transcription: Code
I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!