i am relative new to typescript (coming from java) and i have currently the following problem:
Given: String with a length of 3, it can only contain the charts '0', '1' and '2'. Each of them are representing a different state. Lets assume here the following: '0' -> 'no', '1' -> 'yes', '2' -> 'unknown'. What is the most readable and simplified way to implement it? Currently i am just using simple if functions which are checking what state i have at every index, like:
let state: 'no' | 'yes' | 'unknown';
if (input[1] === '0') {
state = 'locked';
} else if (input[1] === '1') {
state = 'unlocked';
} else {
state = 'unknown';
}
Thanks :)