-정수가 담긴 리스트 num_list가 주어질 때, num_list의 원소 중 짝수와 홀수의 개수를 담은 배열을 return 하도록 solution 함수를 완성해보세요.
num_list의 길이 ≤ 100num_list의 원소 ≤ 1,000| numbers | num1 |
|---|---|
| [1,2,3,4,5] | [2,3] |
| [1,3,5,7] | [0,4] |
입출력 예 #1
입출력 예 #2
function solution(num_list) { return [ num_list.filter((num) => num % 2 === 0).length, num_list.filter((num) => num % 2 === 1).length, ]; }
const words = ['spray', 'limit', 'elite', 'exuberant', 'destruction', 'present'];
const result = words.filter(word => word.length > 6);
console.log(result);
// Expected output: Array ["exuberant", "destruction", "present"]
arr.filter(callback(element[, index[, array]])[, thisArg])
callback
true를 반환하면 요소를 유지하고, false 를 반환하면 버립니다.다음 세 가지 매개변수를 받습니다.
element
index Optional
array Optional
filter를 호출한 배열.thisArg Optional
callback을 실행할 때 this로 사용하는 값.https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/filter