Quote:
Originally Posted by suzzer99
Seems ok(?) except x being 15 or empty string seems bad. And unless labels_show_histogram came from some other out-of-our-control weird source, I'd be comfortable w/o the "=== true" part. (Typescript ftw)
Also for the love of god 8-space tabs. I just cannot. It's like "where did the next line go?" (swivels head) "Oh way over here".
Code:
categories: _.map(colors, function (value, index) {
return labels_show_histogram ? sentimentGroups[index] : index + 1;
}),
labels: {
rotation: labels_show_histogram ? -60 : 0,
x: labels_show_histogram ? "15" : ""
}
Fixed?
Hardly. Grue is right, the original is pretty bad. In addition to the problems you fixed, should be using js naming conventions, should be using shorter, better variable names, for the love of god should not be using the monstrous underscore for a well supported js feature.
other mistakes which may be defensible / are more opinion based: should be using es6 arrow functions when appropriate (if you need full browser support, add a compilation step to your build process). inside arrow functions, use one-letter variables names and "i" for index -- local context usually makes additional clarity unnecessary in this particular case.
Code:
categories: colors.map((x, i) => showHistogram ? sentimentGroups[i] : i + 1),
labels: {
rotation: showHistogram ? -60 : 0,
x: showHistogram ? '15' : ''
}
most likely, the data structures themselves are poorly designed, but it's impossible to tell from this short out of context snippet