Generate Odd Numbers
EasyReturn an array containing all odd numbers from 1 to n (inclusive). Return empty array if n < 1.
Constraints
- n is an integer
- n can be negative, zero, or positive
- Return new array, do not modify inputs
Examples
| Input | Expected Output |
|---|---|
| printOddNumbers(10) | [1, 3, 5, 7, 9] |
| printOddNumbers(5) | [1, 3, 5] |
| printOddNumbers(0) | [] |
Write your solution and click “Run tests” to see results here.