A resistor is a common electrical component found in every electronic circuit. Usually a resistor has a color-based code (as painted bands over it) to decipher through a table.
Color | Digits | Magnitude | Tolerance | T.C.R. |---|---|---|---|---|---| | Black | 0 | 0 | - | - | Brown| 1| 1 | ±1% | 100ppm/k | Red | 2 | 2 | ±2% | 50ppm/k | Orange | 3 | 3 | - | 15ppm/k | Yellow | 4 | 4 | - | 25ppm/k | Green | 5 | 5 | ±0.5% | - | Blue | 6 | 6 | ±0.25% | 10ppm/k | Violet | 7 | 7 | ±0.1% | 5ppm/k | Gray| 8 | 8 | ±0.05% | - | White| 9 | 9 | - | - | Gold| - | -1 | ±5% | - | Silver| - | -2 | ±10% | -
Starting from the left assign a number to each coloured band:
Then, when numbers have replaced colors:
Given an array of colors you must return the resistor resistance, tolerance and (eventually) the TCR as a string (with identifiers separated by spaces between them).
resistorCode(["red", "yellow", "blue", "green"]) ➞ "24MΩ ±0.5%"
// red + yellow = 24; blue = 10^6, green = ±0.5%
// resistance * magnitude = 24000000 (24M)
resistorCode(["white", "black", "white", "blue", "gold"]) ➞ "909MΩ ±5%"
// white + black + white = 909
resistorCode(["black", "white", "black", "orange", "red", "yellow"]) ➞ "90kΩ ±2% 25ppm/k"
// black + white + black = 090 = 90; orange = 10^3
// resistance * magnitude = 90000 (90k)