-2

I had got a question in my exam as follow:

we need to create function that will receive 1 array of all positive number and return all the duplicate values of the array in sorted order.

Here is the solution that I had implemented:

function solution(arr) {
  return arr.filter((value,index)=>arr.indexOf(value)!==index).sort()
}

But the code was rejected. Can someone tell me what could be more optimized solution for this problem in Javascript?

1 Answers1

-1

maybe because of this : solution(['sada','sada','r',4,'r','r']) => ['r', 'r', 'sada'] or solution([2,2,1,3,3,6,7,7,7]) => [2, 3, 7, 7]

your solution when array have same thing more than 2 times, return wrong array .

Sadaf Ziya
  • 37
  • 4