Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SleeplessByte opened this issue Sep 26, 2019 · 0 comments
Open

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

SleeplessByte opened this issue Sep 26, 2019 · 0 comments

Comments

@SleeplessByte
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant