📚

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.