-3
Array = [40, 2, 40, 10, 5, 6, 10, 5, 6, 18, 15]

Sort the array to bring out homogeneous element

C.OG
  • 6,236
  • 3
  • 20
  • 38
  • Your array is invalid syntax. – ASDFGerte Dec 28 '19 at 09:47
  • what does not work? – Nina Scholz Dec 28 '19 at 09:47
  • The syntax is wrong I guess u know Wat I meant – iamgabrielsoft Dec 28 '19 at 09:49
  • Hi, welcome to Stack Overflow. We are a community of volunteers passionate about programming and computer science. Nobody here offers a professional service to answer questions. If you want a question to be answered, you should take some effort to ask your question. You should elaborate your problem and what you have done so far to solve it. What have you researched so far? What code did you write and what's the problem with it?. Have a look at [ask] to get help. – Lutz Dec 28 '19 at 09:57

1 Answers1

2

You could take a Set and filter the values who are alreday seen.

var array = [40, 2, 40, 10, 5, 6, 10, 5, 6, 18, 15],
    seen = array.filter((s => v => s.has(v) || !s.add(v))(new Set));

console.log(seen);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392