Explanation:
The Set object lets you store unique values of any type.
That is why new Set([1,2,1,3,3,4]) will give a set of 1,2,3,4. Since a set is iterable whe can spread it into an new array, thus creating a new array containing only the unique values of the input array.
const uniqueValues = [...new Set(input)] can be written as follows:
The unique input values are then filtered with .filter()checking if each and every value is in the winning sequence using winSequence.includes(value).
This will result in an intersection between the unique values in the input array and the winning sequence. Then if the length of that intersection is the same as the length of the winning sequence, that means a "WIN".
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
JavaScript version:
Explanation:
The
Set
object lets you storeunique
values of any type.That is why new
Set([1,2,1,3,3,4])
will give a set of1,2,3,4
. Since a set is iterable whe can spread it into an new array, thus creating a new array containing only the unique values of the input array.const uniqueValues = [...new Set(input)]
can be written as follows:The unique input values are then filtered with
.filter()
checking if each and every value is in the winning sequence usingwinSequence.includes(value)
.This will result in an intersection between the unique values in the input array and the winning sequence. Then if the length of that intersection is the same as the length of the winning sequence, that means a "WIN".