Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
In the problem statement, the colors and its code are already mentioned. So first let us define an array of colors.

```
export const COLORS = [
'black',
'brown',
'red',
'orange',
'yellow',
'green',
'blue',
'violet',
'grey',
'white',
]
```

Now we have an array, we can directly get code by fetching the index of the parameter color in the array and use the Array.indexOf() to achieve our results.

```
export const colorCode = (color: string) => {
return COLORS.indexOf(color);
}
```