Open joshgoebel opened 2 years ago
I do think that:
function colorValue(color) {
return resistorBands[color]
}
is more idiomatic and readable than
resistorBands[firstColor]
...but I do agree it's less problematic.
But really that's a just naming concern, IMHO. (I personally think colorValue
is not great naming here) The lookup table should be named such as to fully indicate its purpose.
So I don't see a significant difference in expressiveness between:
// object literal
COLOR_to_RESISTANCE[tensColor] * 10 + COLOR_to_RESISTANCE[onesColor]
// function dispatch
colorToResistance(tensColor) * 10 + colorToResistance(onesColor)
Wrapping the object literal in a function dispatch just starts to feel like needless abstraction to me - and I've certainly steered students aways from such needless wrapping in other cases for sure.
I don't feel the auto-intelligence should flag either of the above solutions.
That's a good case. Ok. I agree with your assessment :)
Describe the incorrectness
I don't think the analyzers advice makes any sense here:
The advice assumes a student is using an array - in which case there is complexity to hide and I agree a function as a named abstraction is useful, but in this case a well-named lookup table is serving the same purpose as a function, so the advice makes little sense.
Which exercise
Resistor Duo
Source file(s)
Expected analysis
None. (well at least not on this point)
Additional context
None.