javascript-analyzer icon indicating copy to clipboard operation
javascript-analyzer copied to clipboard

Improve resistor-color-duo: handle solutions based on reduce

Open SleeplessByte opened this issue 5 years ago • 0 comments

Currently, when a solution contains reduce, we explicitly bail out early. The following two examples should be considered approvable, but not optimal. Both should come with a hint.

const value = (colors) => {
    return Number(
        colors
          .slice(0,2)
          .reduce((digits, color) => digits + colorCode(color), '')
    )
}

Use the type-juggling message hint.

function value(colors) {
    return colors
      .slice(0,2)
      .reduce((value, color, index) => value + colorCode(color) * Math.pow(10, 1 - index), 0)
}

Use a new hint: Is reduce really the best candidate when trying to get the sum of significant digit values, when there are two values only.

Which exercise

resistor-color-duo

SleeplessByte avatar Sep 26 '19 14:09 SleeplessByte