TIL_프로그래머스 - Lv0. 배열의 유사도

정윤숙·2023년 6월 11일
0

TIL

목록 보기
167/192
post-thumbnail

📒 오늘의 공부

1. 프로그래머스

Lv0. 배열의 유사도

나의 풀이

const solution=(s1, s2)=> {
    let answer = 0;
    for(let i=0; i<s1.length; i++){
        if(s2.includes(s1[i])){
            answer+=1
        }
    }
    return answer;
}

다른 풀이

function solution(s1, s2) {
    const intersection = s1.filter((x) => s2.includes(x));
    return intersection.length;
}
  • filter 쓰기!!
profile
프론트엔드 개발자

0개의 댓글