12345678910111213141516171819202122232425262728293031 |
- export function decodedValue(colors: string[]): number {
- if (colors.length < 2) {
- throw new Error("Unexpected number of colors");
- }
- // Ignore extra colors.
- colors = colors.slice(0, 2);
- const res = colorCode(colors[0])*10+colorCode(colors[1]);
- return res;
- }
- export const colorCode = (name: string): number => {
- const num = COLORS.indexOf(name.toLowerCase())
- if (num == -1) {
- throw new Error(`Invalid color name "${name}"`);
- }
- return num;
- }
- export const COLORS: string[] = [
- 'black',
- 'brown',
- 'red',
- 'orange',
- 'yellow',
- 'green',
- 'blue',
- 'violet',
- 'grey',
- 'white',
- ];
|