-
[프로그래머스 level.1] filter , includes알고리즘 2023. 6. 20. 11:22
로또의 순위
function solution(lottos, win_nums) { let countZero = lottos.filter(x => x===0).length; //0의개수 let sameNum = lottos.filter(x => win_nums.includes(x)).length; //같은 개수 let num1 = 7 - (sameNum + countZero === 0 ? 1 : sameNum + countZero); let num2 = 7 - (sameNum === 0? 1 : sameNum); let answer = [num1, num2] return answer; }
쓰면서 생각이 든건데 변수명 작명을 좀 못하는 것 같다 나중에 다시 볼때 가독성을 높이기 위해서 조금은 고민하고 변수를 쓸까생각이 들었다(갑자기)
filter 거름망을 통해서 걸러내는 중에 또 다시 includes를 까먹고 in 함수를 찾고 있다(파이썬의 피해)
항상 includes를 기억합시다
'알고리즘' 카테고리의 다른 글
[프로그래머스 level.1] 내림차순정렬, 아스키코드 변환 (0) 2023.06.21 [프로그래머스 level.1] slice 스파르타 예습 (0) 2023.06.20 [프로그래머스 level.1] 이중반복문, 중복제거, 정렬 (0) 2023.06.20 [프로그래머스 level.1] 06.19 (0) 2023.06.19 알고리즘 Day-1 (0) 2023.06.16