题解 | #配置文件恢复#
配置文件恢复
https://www.nowcoder.com/practice/ca6ac6ef9538419abf6f883f7d6f6ee5
const obj = { 'reset board': 'board fault', 'board add': 'where to add', 'board delete': 'no board at all', 'reboot backplane': 'impossible', 'backplane abort': 'install first', } while(line = readline()){ let res = 'unknown command' const arr = line.split(' ') if(arr.length === 1){ let index = 'reset'.indexOf(arr[0]) if(index===0){ res = 'reset what' } } if(arr.length === 2){ const arr1 = [] for(let key in obj){ const keyArr = key.split(' ') let index1 = keyArr[0].indexOf(arr[0]) let index2 = keyArr[1].indexOf(arr[1]) if(index1===0&&index2===0){ arr1.push(obj[key]) } } if(arr1.length===1){ res = arr1[0] } } console.log(res) }