π
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.