대충 만든 자판

전민승·2023년 3월 1일
0
function solution(keymap, targets) {
    
    var answer = [];
    let pressKey= 0;
    
    targets.forEach(target=>{
        for(let i=0; i<target.length; i++){
            let count= Infinity;
            
            keymap.forEach(key=>{
                let idx = key.indexOf(target[i])
    
                if(idx>-1){
                    count = Math.min(count, idx+1)
                }
            })
            pressKey+=count
        }
        answer.push(pressKey)
        pressKey=0;
    })
    
    answer = answer.map(x=>{
        if(x==Infinity){
            x=-1
        }
        return x
    })
    
    
    return answer;
}
profile
Frontend Developer

0개의 댓글