diff --git a/tracks/typescript/exercises/resistor-color/mentoring.md b/tracks/typescript/exercises/resistor-color/mentoring.md new file mode 100644 index 000000000..3733e2826 --- /dev/null +++ b/tracks/typescript/exercises/resistor-color/mentoring.md @@ -0,0 +1,27 @@ +### Topics Covered: +1. Array in Typescript +2. Get index using inbuilt function + +In the problem statement, the colors and their 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 using the Array.indexOf() to achieve our results. + +``` +export const colorCode = (color: string) => { + return COLORS.indexOf(color); +} +```