πŸ“š

Filter Even Numbers

Filter Even Numbers
쉬움 λ°°μ—΄ +10pts

Problem

Write a function that returns only the even numbers from an array.

Examples

Input: filterEvens([1, 2, 3, 4, 5, 6])
Output: [2, 4, 6]

Explanation

이 λ¬Έμ œλŠ” **filter λ©”μ„œλ“œ**λ₯Ό μ‚¬μš©ν•˜μ—¬ 쑰건에 λ§žλŠ” μš”μ†Œλ§Œ μ„ νƒν•˜λŠ” 방법을 ν•™μŠ΅ν•©λ‹ˆλ‹€. **filter λ©”μ„œλ“œμ˜ λ™μž‘** filterλŠ” λ°°μ—΄μ˜ 각 μš”μ†Œμ— λŒ€ν•΄ 콜백 ν•¨μˆ˜λ₯Ό μ‹€ν–‰ν•˜κ³ , trueλ₯Ό λ°˜ν™˜ν•˜λŠ” μš”μ†Œλ§Œ λͺ¨μ•„ μƒˆ 배열을 λ§Œλ“­λ‹ˆλ‹€. `arr.filter(callback)`μ—μ„œ: - callback이 true λ°˜ν™˜ β†’ ν•΄λ‹Ή μš”μ†Œ 포함 - callback이 false λ°˜ν™˜ β†’ ν•΄λ‹Ή μš”μ†Œ μ œμ™Έ **λ°°μ—΄ [1, 2, 3, 4, 5, 6]의 처리 κ³Όμ •** - 1 % 2 === 0 β†’ false (μ œμ™Έ) - 2 % 2 ===...

View detailed explanation β†’

Key Concepts

filter λ©”μ„œλ“œ 콜백 ν•¨μˆ˜ 쑰건뢀 필터링 ν™”μ‚΄ν‘œ ν•¨μˆ˜
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.