You need to develop a function that takes an array of numbers and returns a new array containing only the unique numbers. What approach would you use to filter out the duplicates?

  • Using a for loop and checking uniqueness manually
  • Using Array.prototype.filter() and a custom filter function
  • Using Array.from(new Set(array))
  • Using Array.prototype.reduce() with a custom accumulator function
To filter out duplicate numbers in an array, you can use Array.from(new Set(array)). This creates a Set from the array (which only keeps unique values) and then converts it back to an array. It's a concise and efficient approach for this task.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *