πŸ“š

Filter Positive Numbers

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

Problem

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

Examples

Input: filterPositive([-1, 0, 1, 2, -3])
Output: [1, 2]

Explanation

이 λ¬Έμ œλŠ” **filter λ©”μ„œλ“œ**둜 쑰건에 λ§žλŠ” μš”μ†Œλ§Œ μ„ νƒν•˜λŠ” 방법을 ν•™μŠ΅ν•©λ‹ˆλ‹€. **μ–‘μˆ˜ 쑰건** μ–‘μˆ˜λŠ” 0보닀 큰 μˆ˜μž…λ‹ˆλ‹€: `x > 0` **filter λ™μž‘** 콜백이 trueλ₯Ό λ°˜ν™˜ν•˜λŠ” μš”μ†Œλ§Œ μƒˆ 배열에 ν¬ν•¨λ©λ‹ˆλ‹€. **[-1, 0, 1, 2, -3] 필터링** - -1 > 0 β†’ false (μ œμ™Έ) - 0 > 0 β†’ false (μ œμ™Έ) - 1 > 0 β†’ true (포함) - 2 > 0 β†’ true (포함) - -3 > 0 β†’ false (μ œμ™Έ) - κ²°κ³Ό: [1, 2]...

View detailed explanation β†’

Key Concepts

filter λ©”μ„œλ“œ μ–‘μˆ˜ 쑰건 λ°°μ—΄ 필터링 비ꡐ μ—°μ‚°
Time: O(n) Space: O(n)
solution.js
Ctrl + Enter
Run tests to see results here.