[Lv.0] 짝수 홀수 개수

01수정·2022년 11월 10일
0
post-thumbnail

<입문 100문제> Day 6 - 문자열, 반복문, 출력, 배열, 조건문

문제


풀이

function solution(num_list) {
    let even = num_list.filter((num) => num % 2 ===0).length
    let odd = num_list.length - even;
    return [even, odd]
}

해답

function solution(num_list) {
  const evenLength = num_list.filter(n => n % 2 === 0).length;
  return [evenLength, num_list.length - evenLength];
}
profile
새싹 FE 개발자

0개의 댓글