const-tommy.dev
기록을 불러오는 중입니다
cards1과 cards2에서 지금 몇 번째 카드를 쓸 차례인지 알려주는 인덱스 변수(cards1Idx, cards2Idx)를 0부터 시작하게 만들기goal에 있는 단어들을 하나씩 꺼내면서, 이게 지금 cards1의 맨 앞에 있는지 아니면 cards2의 맨 앞에 있는지 순서대로 대조해본다. 일치하는 게 있다면 그 뭉치의 인덱스를 하나 올려서 다음 카드를 비교할 준비// 풀이 코드를 작성하세요.
/*
goal에서 cards1, cards2에 해당하는 원소들이 갖는 인덱스를 비교하자
*/
function solution(cards1, cards2, goal) {
let cards1Idx = 0;
let cards2Idx = 0;
for (const value of goal) {
if (cards1Idx < cards1.length && cards1[cards1Idx] == value) {
cards1Idx ++;
} else if (cards2Idx < cards2.length && cards2[cards2Idx] == value) {
cards2Idx ++;
} else {
return "No";
}
}
return "Yes";
}