Please see https://github.com/exercism/javascript-analyzer/issues/49#issuecomment-1401342382.
this exercise now uses functions, not methods
Thanks for getting back to me.
So the first iteration I had is as follows. I couldn't figure out how to link to it, so here it is verbatim.
const codes = {
black: 0,
brown: 1,
red: 2,
orange: 3,
yellow: 4,
green: 5,
blue: 6,
violet: 7,
grey: 8,
white: 9
};
export const decodedValue = ([first, second]) => {
return codes[first] * 10 + codes[second];
};
This clearly doesn't use a helper, and I suppose the analyser has looked for the array member syntax in decodedValue
.
I then changed it to still use the object, but have a second function as a helper after reading this thread.
const codes = {
black: 0,
brown: 1,
red: 2,
orange: 3,
yellow: 4,
green: 5,
blue: 6,
violet: 7,
grey: 8,
white: 9
};
const decode = (color) => {
return codes[color];
};
export const decodedValue = ([first, second]) => {
return decode(first) * 10 + decode(second);
};
The analyser now still finds an issue, but it doesn't tell me what the issue is. Here's a screenshot. I tried to reload the page a few times, but this is consistent. It doesn't have a message.
I just found this by googling the Using a helper method is good practice, because it replaces a cryptic "member call" with a named call that can be documented individually message, which the automatic code analysis showed me. I was very confused about what the analyser wanted from me. That helper is a function, not a method. There's no class in my code, so it can't be a method. I thought it was talking about Array.indexOf()
, but my solution had an object, so that made little sense. I think the wording of that advice is unlucky.
I had a hard time making it produce the output the instructions suggested. :)
Fix typo in example output
I had a hard time making it produce the output the instructions suggested. :)
Broken markdown in regex explanation