Finished
44//
55
66export class ResistorColorTrio {
7 constructor() {
8 throw new Error('Remove this line and implement the function');
7 constructor(colors) {
8 // Edge Case: Missing or empty colors array
9 if (!colors || colors.length === 0) {
10 throw new Error('missing colors');
11 }
12
13 // Edge Case: Less than 3 colors provided
14 if (colors.length < 3) {
15 throw new Error('missing colors');
16 }
17
18 this.colors = colors;
19 this.colorValues = {
20 'black': 0,
21 'brown': 1,
22 'red': 2,
23 'orange': 3,
24 'yellow': 4,
25 'green': 5,
26 'blue': 6,
27 'violet': 7,
28 'grey': 8,
29 'white': 9
30 };
931 }
1032
11 label() {
12 throw new Error('Remove this line and implement the function');
33 get label() {
34 const [first, second, third] = this.colors;
35
36 // Edge Case: Invalid color names
37 if (!(first in this.colorValues) || !(second in this.colorValues) || !(third in this.colorValues)) {
38 throw new Error('invalid color');
39 }
40
41 const firstValue = this.colorValues[first];
42 const secondValue = this.colorValues[second];
43 const zeros = this.colorValues[third];
44
45 // Calculate the base value
46 const baseValue = firstValue * 10 + secondValue;
47
48 // Calculate the total ohms value
49 let ohms = baseValue * Math.pow(10, zeros);
50
51 // Determine the appropriate unit based on the magnitude
52 let unit = 'ohms';
53 if (ohms >= 1000000000) {
54 ohms = ohms / 1000000000;
55 unit = 'gigaohms';
56 } else if (ohms >= 1000000) {
57 ohms = ohms / 1000000;
58 unit = 'megaohms';
59 } else if (ohms >= 1000) {
60 ohms = ohms / 1000;
61 unit = 'kiloohms';
62 }
63
64 return `${ohms} ${unit}`;
1365 }
1466}
67
68// Handled Edge Cases: missing colors array, less than 3 colors provided, invalid color names
Test NameStatus
Orange and orange and black
Fail
Blue and grey and brown
Fail
Red and black and red
Fail
Green and brown and orange
Fail
Yellow and violet and yellow
Fail
Blue and violet and blue
Fail
Minimum possible value
Fail
Maximum possible value
Fail
First two colors make an invalid octal number
Fail
Ignore extra colors
Fail
Invalid color
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.