Skip to content

Commit 2306c93

Browse files
author
programmiri
committed
Solve excercise Resistor Color Duo with array
1 parent 13be898 commit 2306c93

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed
Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
1-
const colorMap = {
2-
black: 0,
3-
brown: 1,
4-
red: 2,
5-
orange: 3,
6-
yellow: 4,
7-
green: 5,
8-
blue: 6,
9-
violet: 7,
10-
grey: 8,
11-
white: 9,
12-
};
1+
const colorMap = [
2+
'black',
3+
'brown',
4+
'red',
5+
'orange',
6+
'yellow',
7+
'green',
8+
'blue',
9+
'violet',
10+
'grey',
11+
'white',
12+
];
1313

1414
function value(colorNameList) {
15-
const accNumbers = colorNameList
16-
.map((colorName) => {
17-
return colorMap[colorName];
18-
})
15+
const numAsString = colorNameList
16+
.reduce((acc, curr) => {
17+
acc.push(colorMap.indexOf(curr));
18+
return acc;
19+
}, [])
1920
.join('');
20-
return parseInt(accNumbers);
21+
return Number(numAsString);
2122
}
2223

2324
export { value };

0 commit comments

Comments
 (0)