Filter Unique Positive Numbers from an Array

You're tasked with creating a system that filters out negative and duplicate numbers from a list of data. The system should only retain unique positive numbers from the input. This is important for a feature that requires clean and precise data input.

Instructions:

  • Write a function named uniqueArr that takes one parameter:

    • arr: An array of integers, which can include both positive and negative numbers.
  • The function should return a new array that includes only unique positive numbers (greater than 0) from the input array.

Note: Only use the map, filter, or reduce methods, or a combination of these methods, to solve the problem. Do not use loops to iterate or perform the operation.

Example 1

Input: uniqueArr([4, 4, -2, 0, 2, 9, 9]);
Output: [4, 2, 9]

Example 2

Input: uniqueArr([-10, -20, -30]);
Output: []

Example 3

Input: uniqueArr([5, -3, 6, -8, 5, 1, 6]);
Output: [5, 6, 1]

Are you stuck on this problem?

Get detailed, step-by-step solution and improve your JavaScript skills.

  • Detailed Explanation: Each solution comes with a comprehensive explanation, helping you understand the logic and concepts thoroughly.
  • Learn to Write Better Code: Even if you have written the code, discover ways to improve it and adopt best practices.
  • Save Time: Don’t waste hours struggling—get the solution and learn efficiently.
  • Lifetime Access: Get access to lifetime solutions for all problems available
Get the Solution

" I struggled with this problem for hours, but the solution provided here was clear and easy to follow. It helped me understand where I went wrong and improved my coding skills significantly." - Jane D.

If you're not satisfied, I offer a 7-day money-back guarantee.