Finished
88 * @param {string[]} colors
99 */
1010 constructor(colors) {
11 throw new Error('Remove this line and implement the function');
11 if (colors.length < 3) {
12 throw new Error('At least three colors need to be present');
13 }
14
15 this.colors = colors;
16 this.colorValues = {
17 'black': 0,
18 'brown': 1,
19 'red': 2,
20 'orange': 3,
21 'yellow': 4,
22 'green': 5,
23 'blue': 6,
24 'violet': 7,
25 'grey': 8,
26 'white': 9
27 };
1228 }
1329
1430 /**
1531 * @returns {string}
1632 */
1733 label() {
18 throw new Error('Remove this line and implement the function');
34 // Edge Case: Invalid color inputs not in the defined color list
35 if (!this.colorValues.hasOwnProperty(this.colors[0]) ||
36 !this.colorValues.hasOwnProperty(this.colors[1]) ||
37 !this.colorValues.hasOwnProperty(this.colors[2])) {
38 throw new Error('Invalid color');
39 }
40
41 const firstValue = this.colorValues[this.colors[0]];
42 const secondValue = this.colorValues[this.colors[1]];
43 const zeros = this.colorValues[this.colors[2]];
44
45 // Edge Case: Handle calculation of the resistance value
46 let resistance = (firstValue * 10 + secondValue) * Math.pow(10, zeros);
47
48 // Edge Case: Convert to appropriate metric prefix based on magnitude
49 if (resistance >= 1000000000) {
50 return `${resistance / 1000000000} gigaohms`;
51 } else if (resistance >= 1000000) {
52 return `${resistance / 1000000} megaohms`;
53 } else if (resistance >= 1000) {
54 return `${resistance / 1000} kiloohms`;
55 } else {
56 return `${resistance} ohms`;
57 }
1958 }
2059}
60
61// Handled Edge Cases:
62// 1. Invalid color inputs not in the defined color list
63// 2. Empty or missing color inputs (through constructor check)
64// 3. Conversion to appropriate metric prefixes (kilo, mega, giga)
65// 4. Proper calculation of resistance values based on color codes
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
Fail

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