const status= [1,1,1,2] .filter ((s, i, self)= >
  let prev= i--
  if (prev >
0) {
    return self [prev]!== self [i]
console.log (status)

In this filter, I compare the previous element with the current one, but in the end it only returns [2] to me, but it should return [1,2] because 2!== 1. Can you please help with the filter

Everything returns correctly .. 2 of course!= 1 .... Therefore, the last iteration is two and returns

Алексей Шиманский2021-10-14 02:21:10

But according to what logic there should be 1 -it is not clear. In general, what is the task?

Алексей Шиманский2021-10-14 02:21:10

If you want to get an array of values ​​without duplicates (filter /remove repetitions of its elements), then const filtered= [... new Set (arr)];

yar852021-10-14 02:21:10